I’m a freshman to jQuery. I think it’s reasonable that jQuery could manipulate elements added by code, but I found it couldn’t just now.
$(function(){
$("#addVideo").click(function(){
$("#publisher").append("<div id='choseType'><input type='button' value='video'> <input value='music' type='button'> <input type='button' value='X'></div>");
})
$("#choseType input:eq(0)").click(function(){
$(this).addClass("selected");
})
})
Is it jquery’s limitation or my code’s fault? It seems if I put the second click() function into the first one it will run correctly, but it will only run once(if I remove the appended #choseTypeand append it again the second click won’t work.).Then how do I manipulate code added elements? Thanks!
1 Answer