Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
How can I target a button within a temperate literal, for use in a separate click function?

Currently, Im using temperate literals to generate buttons to go along with locally stored data per result. This data is generated via a click which handles calling the storage to get back the information, displaying it a container. However, when I want to target the button, it's unresponsive.

My code

$(document).ready(() => {
    const genMonthlyQueueBtn = $("#genMonthlyQueue");
    const genTransientQueueBtn = $("#genTransientQueue");  
    

    const monthlyPlateQueue = () => {
        const $insertMonthly = $('#insertMonthlyPlates');
        $insertMonthly.empty();
        let monthlyPlates = JSON.parse(localStorage.getItem('Monthly Plates'));
        for (i = 0; i < monthlyPlates.length; i++) {
            console.log(monthlyPlates);
            $insertMonthly.append(`
            <div class="container" id="generatedMonthlyPlates">
            <input type="text" width="100px" name="monthlyLicensePlate" id="monthlyLicensePlate" class="licensePlate" placeholder="AB12345" value=${monthlyPlates[i]}/>
            <div class="text-center">
            <button class="btn btn-warning" type="submit" id="editMonthlyPlate" name="action">Edit
            <i class="material-icons right">edit</i>
            </button>
            <button class="btn btn-danger" type="submit" id="deletePlate" name="action">Delete
            <i class="material-icons right">delete</i>
            </button>
            </div>
            </div>
            `)
        }

    }    
    // get the array from local storage through queue function
    genMonthlyQueueBtn.click(() => {
        monthlyPlateQueue();
    })
    // call generated button and test functionality to edit and push back to storage
    const editMonthlyPlateBtn = $('#editMonthlyPlate');
    const editMonthlyPlate = () => {
        console.log('I was clicked');
    }
    editMonthlyPlateBtn.click(() => {
        editMonthlyPlate();
    })

Is there a better way to do this? or am I going about it the wrong way? This data is triggered with a previous button click, and when adding an onClick function to the button itself, It's just called every time I generate the list and not when I clicked the button itself which is expected but not what I need.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!