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

156
Views
Onclick is only triggered once after assigning functions through for loop

In those for loop, I am assigning a function to a close button that will essentially remove a mark tag from some text.

    for (q = 0; q < json_response.trainer.annotation.length; q++) {
        let close_ = document.getElementById(`cl_${x3}_${q}`);
        console.log(close_)
        close_.onclick = function () {
            delete_ent(this);
        };
    };


function delete_ent($this) {
    let all_text = $this.parentNode.parentNode.innerHTML;
    console.log($this, $this.parentNode);
    let test1 = $this.parentNode.innerHTML;
    let replace_text = test1.split("<span>");
    // console.log(replace_text[0]);
    let updated_text = all_text.replace(`${$this.parentNode.outerHTML}`, `${replace_text[0]}`);
    $this.parentNode.parentNode.innerHTML = updated_text;
}

It works exactly as intended for the first mark tag removed, but then after it's updated the text, the other close buttons stop working.

This is for a chrome extension

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!