JQuery click for elements added using Ajax -
JQuery click for elements added using Ajax -
this question has reply here:
jquery getting id of clicked link 6 answersi have div class c
, adding code class using ajax ends looking like:
<div class="c"> <div class="del" id="1"></div> <div class="del" id="2"></div> <div class="del" id="3"></div> </div>
my class c
static , divs class delete
added using ajax. want id of div class delete
click on.
i first doing:
$(".delete").click(function(){ var id = $(this).attr('id'); } );
but doesn't work. later found out on should utilize .on()
content added using ajax. understood, implemented next way:
$(".c").on('click','.delete',function(){ var id = $(".delete").attr('id'); } );
but gives me id
of first delete. please provide way can id
of delete clicked on assuming inner divs, namely:
<div class="del" id=i></div>
are added using ajax. give thanks you.
you don't have reselect .delete
collection 1 time again $('.delete')
. .attr
method invoked getter on collection of elements, returns attribute value of first element in collection. in case have reference clicked element this
. seek this:
$(".c").on('click','.delete', function() { var id = this.id; });
also can access id
htmlelement property, don't need read attribute.
jquery ajax
Comments
Post a Comment