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
Post a Comment