I have a <div> list with the same html but with different values inside html. The hierarchy is as follows:
<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 the case, I insert html at the top of the list, which is another <div id="element> ... </div>
I have the following event handler for clicking a comment icon,
$('.commenticon').click(function(){ $(this).closest('.actionframe').next('nav').slideToggle(300); return false; });
It works correctly until I inserted a new <div id="element> ... </div> . The comment icon click event handler does not match. I looked for this problem, everyone said that .delegate() should be used.
My problem is that I do not know where to use the delegate function. I used to get results from ajax to enter <div id="element> ... </div> , I used the .delegate() function in an ajax call that introduces 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; }); } });
This is currently not working. So, any ideas how to make this thing work?
source share