websss
asked on
append li to ul in jquery - onClick stopped working for newly added item
I'm facing an issue where i add a new LI to a UL and i'm unable to click it
Based on what i've read its to do with delegates and event handlers
Here is the click event for the LI
Here is how i add the LI
should this work? or am i doing anything wrong (aside from using numbers for Id's
Based on what i've read its to do with delegates and event handlers
<ul id="SchemeList" class="list-group">
<li id="71" class="list-group-item">
<a href="#">namegoeshere</a>
</li>
</ul>
Here is the click event for the LI
$('#SchemeList li').on('click', function () {
alert(this.innerText);
//...
Here is how i add the LI
<button class="btn btn-success" id="saveNewScheme" type="button" style="">Save New Scheme</button>
$('#saveNewScheme').on('click', function () {
var newSchemeId = 11;
$("#SchemeList").append('<li class="list-group-item" id="' + newSchemeId + '"><a href="#">' + $("#schemeName").val() + '</a></li>');
should this work? or am i doing anything wrong (aside from using numbers for Id's
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome.
ASKER