I have a jquery replace() putting in list items that I want to attach a function to. I don’t know exactly how to do this though.
function replaceListItems(){ $('ul.options').replaceWith('<ul class="options"><li class="btn"><img src="btn.png" /></li></ul>');}
Here’s the function I’d like to attach:
$("ul.options li").click(function(){myFunction()});
Seems like it gets removed if I assign it before the list items gets replaced/created.
Thanks in advance for the help!
-m
Replace:
with:
this way jQuery also attaches the click handler to the replaced/created elements.
Reference: http://api.jquery.com/live/
Demo: http://jsfiddle.net/CWH4D/