jquery - selecting the id of a child element of a dynamically created link -
i trying select id of <li>
element being created under dynamic element, <a>
tag. cannot seem handle on id of <li>
. closest i've got this:
$("a li:first-child").attr('id');
but give id of first li, not 1 being clicked.
here script, have truncated, because first part important:
$.each(... $("#inventorydiv").append("<ul id='invlist'></ul>"); $("#invlist").append("<a href='javascript:void(0);' name='invlink'><li id='" + this.inventory_id + "'> ...
and listener is:
$("#inventorydiv").on('click','a',function(){ console.log($("a li:first-child").attr('id'); }
any thoughts?
$("#inventorydiv").on('click','a',function(){ console.log($(this).find('li').attr('id')); });
Comments
Post a Comment