Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent bootstrap collapse from collapsing


a 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 tipp?

This does not help here

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

Is there a way to prevent the default collapse action?
Thx

like image 464
chris Avatar asked Jun 04 '13 09:06

chris


People also ask

How do I stop a Bootstrap collapse?

To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element. Then add the data-target="#id" attribute to connect the button with the collapsible content (<div id="demo">).

How do you determine if a Bootstrap collapse is opening or closing?

If the collapsible element is closed by default, the attribute on the control element should have a value of aria-expanded="false" . If you've set the collapsible element to be open by default using the show class, set aria-expanded="true" on the control instead.

How do you know if an element has collapsed?

You can determine whether an element is collapsed or not by using the :visible and :hidden selectors. }, "slow" );

What is accordion Bootstrap?

The Bootstrap accordion is a component that organizes content within collapsable items. Accordion allows the display of only one collapsed item at a time. Accordions can toggle through a number of text blocks with a single click, and that greatly enhances the UX of your project.


1 Answers

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 ...
});
like image 126
A. Wolff Avatar answered Oct 11 '22 14:10

A. Wolff