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

276
Views
onclick of child element is causinf parent button to activate

I have 1 function that creates a new checkbox with a delete button to remove it. However when using onclick for the delete button, it causes the it to be deleted when the create checkbox is activated so that nothing is there in the first place.

<script>
    var list = document.getElementById("list");
    var i = 0;

    function add_client(form) {

        var div = document.createElement("div");
        div.setAttribute("id", "div"+i.toString())

        var check = document.createElement("input")
        check.setAttribute("type", "checkbox");
        check.setAttribute("id", "check"+i.toString());

        var label = document.createElement("label");
        label.setAttribute("for", "check"+i.toString());
        label.setAttribute("id", "label")
        txtNode = document.createTextNode(form.value);
        label.appendChild(txtNode);

        var br = document.createElement("br");

        div.appendChild(check);
        div.appendChild(label);
        list.appendChild(div)
        i++;
        

        var del = document.createElement("input");
        del.setAttribute("type", "button");
        del.setAttribute("value", "Delete");
        del.setAttribute("id", "del")
        div.appendChild(del);
        del.onclick = del.remove();

        div.appendChild(br);

    }
</script>

i know this is a DOM issue but cannot get around it.... any ideas?

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!