简体   繁体   中英

Jquery click event propagation on second click after Ajax

Hi i always use this example code to make a div work as link.

<div onclick="location.href='http://www.example.com';" style="cursor:pointer;"></div>

The problem is i have inserted an other javascript action inside (this action need to stay on the current page) the problem is Not the first click but the second..

This javascript actions its an ajax function that "change" that html.. in the fiddle where i have no ajax, its working great, on first, second, third, any clic..

Here is the code http://jsfiddle.net/HzsH9/4/

Im using.. Jquery, also this is the anti propagate code im using

$("a").bind("click", function(e){ alert("clicked!"); e.stopPropagation() });

The outer div class is class="listingsRow"

and the inside javascript goes here

<a id="btn_remove_114" name="btn_remove_114" onclick="ajaxFavouratesRemove(1,114,375);">
                           <div class="fav"></div></a>

After ajax success, its changed for this

 <span id="spadd114"><a id="btn_add_114" name="btn_add_114" onclick="ajaxFavouratesAdd(114);"><div class="nofav"></div></a></span>

Also i just found this, but i cant manage to do the same how to stop event propagation with slide toggle-modified with the updated code.

Classic case of event delegation

$(".listingsRow").on('click','a',function(e){ 
  alert('clicked');
  e.stopPropagation();
})
$('#singles_114').click(function(e){
    e.stopPropagation()
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM