dom - get attributes of an appended element by jquery -


this question has answer here:

i want id of appended element jquery, cant, code: append elements:

$(document).ready(function(){  $("#addslide").click(function(){  var slideid="slide"+n;  var  nslide="<td><img class='projimgs'id='"+slideid+"'onclick='opencustomroxy()' src='' style='width:75px;height:55px'/> <input id='sldaddr' name='"+slideid+"'   type='hidden' value='' /> </td>";  $("#slidetr").append(nslide);   }); 

and code atrribute 'id' :

$(".projimgs").click(function(){ var id= $(this).attr('id'); console.log(id); var source= "http://localhost/exx/admin/fileman/index.html?integration=custom&type=files&img="+id; console.log(source); $("#frame").attr('src',source); }); 

use event delegation added dymanically doms . use immediate parent selector traverse , quickly. if didn't know immedaite parent using $(document) instead

$('#slidetr').on('click', '.projimgs', function(){      // code }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -