1

I have bootstrap dropdown menu. To make it keep on show on click inside dropdown then I set it to JavaScript like this

$('.dropdown-menu').click(function(e)
{
     e.stopPropagation();
});

It works. Then now I have

$(document).ready(function() 
{
     $('body').on("click",'#btn_post',function(e)
     {
          alert("waw");
     }
});

<button class="btn btn-default" id="btn_post">Click</button>

When I click button, I can't see the alert "waw". But when I remove the e.stopPropagation(); the alert will appear.

I want that 2 function can be run without conflict.

halfer
  • 19,824
  • 17
  • 99
  • 186
HiDayurie Dave
  • 1,791
  • 2
  • 17
  • 45

1 Answers1

1

Rather than using stopPropagation use preventDefault it might fix your problem.

stopPropagation is used to make sure the event doesn't bubble up the chain. eg. a click on a <td> tag would also fire click events on it's parent <tr>, and then its parent <table>, etc. stopPropagation prevents this from happening.

preventDefault is used to stop the normal action of an element, eg. preventDefault in a click handler on a link would stop the link being followed, or on a submit button would stop the form being submitted.

for more detail event.preventDefault vs event.stopPropagation

Community
  • 1
  • 1
Ranish Karim
  • 366
  • 1
  • 8