I have a Bootstrap collapse with a button inside the header. On the button is clickEvent.
I want to prevent the collapseEvent when clicking the button. Does anyone have a tip?
This does not help here
$('#buttonId').live("click", function (e) {
e.preventDefault();
// some action ...
});
Is there a way to prevent the default collapse action?
I think you are looking for stopPropagation()
method instead:
$('#buttonId').live("click", function (e) {
e.stopPropagation();
// some action ...
});
If your button is a link (<a>
tag ), you should prevent default too or use return false;
BTW, live is deprecated, you should use .on() delegation syntax instead, e.g:
$(document).on('click', '#buttonId', function(e){
e.stopPropagation();
// some action ...
});