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

176
Views
Appending html elements using Jquery and clicking on it does not working

I have an array which I want to display on a badge therefor I have appended as below

           attachmentArray.forEach((element, index) => {
                console.log(index, element.name)
                attachmentBadge.append(`
                     <div id="attachmentBadge_` + index + `" class="badge bg-navy m-1">
                        <div id="file_list_` + index + `" class="d-flex align-items-center justify-space-between">
                            <span id="file_` + index + `">` + element.name + `</span>
                            <span id="closeAttachmentBtn_` + index + `"   value='` + index + `' class="btn btn-sm text-light closeAttachment">
                                &times;
                            </span>
                        </div>
                     </div>
                `)
            });

I also have a function to trigger a console.log when i clicking on

<span id="closeAttachmentBtn_` + index + `"   value='` + index + `' class="btn btn-sm text-light closeAttachment"> &times; </span>

but when i click it isn't working.


        $("div#attachmentBadge.closeAttachment").click(function() {
            console.log('clicked')
        })

what is the correct method to access the function?

about 4 years ago · Juan Pablo Isaza
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!