简体   繁体   中英

Bootstrap accordion run function before opening

Is there any way to run some function before and accordion it's fully opened?

Here's the code:

            $.each($('.accordion-toggle'),function(){
                $(this).click(function() {
                    if($(this).hasClass("collapsed")){
                         //loading content via ajax
                    };
                });

I tried to use .on('show') functions and changing data-toggle with javascript opening and closing content, but it seems to be very complicated due to existing code.

Try this...

$.each($('.accordion-toggle'),function(){
      $(this).click(function() {
            if($(this).hasClass("collapsed")){
                \\loading content via ajax
            }
      });
});

You forget the ";"...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM