Link to home
Start Free TrialLog in
Avatar of websss
websssFlag for Kenya

asked on

On click event for dynamically generated html - not working

Hi
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

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of websss

ASKER

Awesome, that was easy with your explanation, thanks!
You are welcome.