buttons in clickable div in jquery

2019-08-30 08:25发布

问题:

I have whole div you can click on which toggles the main part of that div. The problem is I also have clickable button in that div and when I click on it it does what it should but also toggles the whole div at the same time!

How can I disable that ?

回答1:

Use event.stopPropagation() on button click

It will stop the propagatotin to the parent

$("#buttonid").click(function(e){
  e.stopPropagation() 
});