Use stopImmediatePropagation() , this will stop the event from bubbling through the DOM of your page:
// Index Page Onclick events $('body').on('click','.menuClass',function(e) { e.preventDefault(); var menuid = $(this).attr('id'); alert(menuid); }); // click on groups html >> this page alert fires twice $('body').on('click','.grpClass',function(e) { e.preventDefault(); e.stopImmediatePropagation(); var menuid = $(this).attr('id'); alert(menuid); });
Here is an example of how this works: JSFIDDLE . If you press test1 , bubbling will be prevented and only one warning will be shown. If you press test2 , the event will not be stopped, and you will receive two warnings.
rsplak
source share