javascript - jQuery: Accessing Elements after adding them with Append -


this question has answer here:

i append input in div:

$("#menuitems").append("<input type='button' id='"+$("#category").val()+"' class='menuitemdelete' value="+$("#category :selected").text()+" ><br>"); 

then want access element class name not give responce. try this:

$(".menuitemdelete").click(function(){      alert("abc");  }); 

and try this:

$(".menuitemdelete").on("click", function(){      alert("abc");  }); 

how can access ?

try :

$("#menuitems").on("click",'.menuitemdelete', function(){    alert("abc"); }); 

consider read event delegation concept dynamic element created yours.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -