John Magnolia
John Magnolia

Reputation: 16793

Twitter bootstrap prevent event from taking place

Is there a way to return false/preventDefault before the hide event for the collapse plugin?

E.g I want to do something like this:

$(".collapse").on('hide', function(e){
    if($(this).hasClass("in"))
        e.preventDefault();
});

This simple example: http://jsfiddle.net/ujgSC/4/ with an accordion, I want to prevent the user from closing all of the accordions by clicking the same item twice.

Upvotes: 0

Views: 93

Answers (1)

jd_7
jd_7

Reputation: 1862

Try prevent event the titles.

$('.accordion-toggle').click(function(){    
   if($($(this).attr('href')).hasClass("in")){        
     console.log('PREVENT');
     return false;
   }
});

Example

Upvotes: 2

Related Questions