I have a list of <div>
s with same html but different values inside html. The hierarchy is the following ;
<div id="element">
<div class="likecomm">
<a class="commenticon" href="#">...some value according to the returning value...</a>
</div>
</div>
<div id="element">
<div class="likecomm">
<a class="commenticon" href="#">...some value according to the returning value...</a>
</div>
</div>
In an event, I inject html to the top of the list which is another <div id="element> ... </div>
I have the following event handler for comment icon click;
$('.commenticon').click(function(){
$(this).closest('.actionframe').next('nav').slideToggle(300);
return false;
});
It works correct until I insert the new <div id="element> ... </div>
. The comment icon click event handler doesn't match. I searched about that problem, all were saying that .delegate()
should be used.
My problem is I don't know where to use the delegate function. Before, I get the results from ajax in order to inject the <div id="element> ... </div>
, I used .delegate()
function in ajax call that injects html.
$.ajax({
success:function(data) {
var html=... // the necessary div html binded with data
// prepend function call()
$('.likecomm').delegate(".commenticon","click" , function() {
$(this).closest('.actionframe').next('nav').slideToggle(300);
return false;
});
}
});
Currently, it doesn't work. So, any ideas how to make this thing work ?