Prevent bootstrap from collapsing


a have a bootstrap collapse with a button inside the header. On the button, click the "Delete" button. I want to prevent collapseEvent when the button is clicked. Does anyone have a tipp?

It will not help here

$('#buttonId').live("click", function (e) { e.preventDefault(); // some action ... }); 

Is there any way to prevent the default collapse action?
thanks

+4
source share
1 answer

I think you are looking instead for the stopPropagation() method:

 $('#buttonId').live("click", function (e) { e.stopPropagation(); // some action ... }); 

If your button is a link ( <a> tag), you should also prevent by default or use return false;

BTW, live is out of date, you have to use . on () instead of deletion syntax, for example:

 $(document).on('click', '#buttonId', function(e){ e.stopPropagation(); // some action ... }); 
+11
source

Source: https://habr.com/ru/post/1484372/


All Articles