JavaScript Click event added to appended html; element not working as anticipated click event on dynamically added element jquery,click event of

OK I am sure I am doing something simple fundamentally wrong but am unable to resolve this issue on my own. I have tried googling and searching this forum and reading through the relevant parts of the jquery documentation.

If you need any further information please let me know. Many thanks in advance.

What I am trying to do:

I have a table showing details of various tests at the bottom of which I have a button to ad a new test. As each test comprises several rows of the table I have a template in a hidden div which I have cloned and appended to the live table. I am the using jquery to add appropriate classes and ids based on a variable integer for the sake of uniqueness. I am also attempting to add a click event to an image within one of the table cell to delete the rows relating to that particular test.

My current function

function newTest(sampleID){
    var testID = $("#testCount").val();
    $("#newTest tr").clone(true)
        .addClass("test"+testID)
        .appendTo("#testsTable"+sampleID);
    $(".newdelbox:first")
        .attr("id","testDelete"+testID)
        .addClass("delbox")
        .removeClass("newdelbox");
    $(".test"+testID).on('click',"#testDelete"+testID,delSample(testID));
    testID++;
    $("#testCount").val(testID);
}

What I need to happen

Function to be called when image is clicked.

What is happening

Function is called only when script is assigned (not clicked). Function will not subsequently run when clicked. I am seeing no errors within the console.

What I have tried

chained to preceeding code:

.click(delSample(testID));
.on("click",delSample(testID));
.bind("click",delSample(testID));

As new line within function:

$(".test"+testID).on('click',"#testDelete"+testID,delSample(testID));
document.getElementById("testDelete"+testID).onclick(delSample(testID));
document.getElementById("testDelete"+testID).addEventListener("click",delSample(testID),false);
Answer:1

try this:

 .click(function(){
  delSample(testID);
  });

OR

.on("click",function(){
   delSample(testID);
  });
Answer:2

I'm trying to accomplish the following with Jquery: When the "No Top" radio-button is "checked" it should disable and "uncheck" any selection done in the Checkbox selection. If the user select ...

I'm trying to accomplish the following with Jquery: When the "No Top" radio-button is "checked" it should disable and "uncheck" any selection done in the Checkbox selection. If the user select ...

I want to create paragraph dynamic,so I wrote the following code. After user click the button, a new paragraph whose innerText is the user's inputs should be added.But I failed, Is there someone can ...

I want to create paragraph dynamic,so I wrote the following code. After user click the button, a new paragraph whose innerText is the user's inputs should be added.But I failed, Is there someone can ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

I'm trying to create a news style marquee at the bottom of my XSL page that shows some information it retrieves from an XML file. What I want it to do is automatically refresh the content of only this ...

I'm trying to create a news style marquee at the bottom of my XSL page that shows some information it retrieves from an XML file. What I want it to do is automatically refresh the content of only this ...

  1. reload iframe content using javascript
  2. reload div content using javascript
  3. reload div content using ajax
  4. reload a div content using jquery
  5. reload content using javascript
  6. reload content using ajax
  7. javascript reload iframe content
  8. reload iframe from javascript
  9. how to reload iframe in javascript

I have an array of letters and numbers. let sortLetters = [ 'R', '1', 'U', '1', 'N', '1', 'D', '1', 'M', '1', 'C', '1' ] I want to sort the types alphabetically, then return the first letter I come ...

I have an array of letters and numbers. let sortLetters = [ 'R', '1', 'U', '1', 'N', '1', 'D', '1', 'M', '1', 'C', '1' ] I want to sort the types alphabetically, then return the first letter I come ...