troubleshooting Question

On click event for dynamically generated html - not working

Avatar of websss
websssFlag for Kenya asked on
3 Comments1 Solution76 ViewsLast Modified:
I have a table with an ADD ROW  button, when i click this button is creates a new row dynamically

I then want to have a click event fire for one of these newly created html elements: <input id='schemeItemSaveLink' type='button' value='save'>
however, the alert: alert('you clicked me again!'); isn't firing

What am i doing wrong?

 $('#addSchemeItemRow').on('click', function () {

                var addRow = "<tr class='schemeItemRow'><td> <input type='text' name='lower' id='txtLowerThreshold'>  </td><td> <input type='text' name='upper' id='txtUpperThreshold'> </td><td><input type='color' id='schemecolor' style='width: 25px; height: 25px;'></td> <td><input id='schemeItemSaveLink' type='button' value='save'></td></tr>";

                //add current row to table
                $('#schemetable tr:last').after(addRow);


            $("#addSchemeItemRow").on("click", "#schemeItemSaveLink", function () {
                alert('you clicked me again!');

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros