DEV Community

Hamid Haghdoost
Hamid Haghdoost

Posted on

Bootstrap open Accordion after Ajax loaded

Accordion is a nice component of Bootstrap. It uses Collapse feature of Bootstrap. It works properly under the hood but sometimes you need to do something different. In my case I needed to click on accordion header, then send an Ajax request and get the content of accordion and then open it. There was not a straigh-forward API or document for that and finally I find it.

    let prevent = true;

    $("#collapseThree").on("", function (e) {
        if (prevent) {
        setTimeout(function () {
            prevent = false;
            prevent = true;
        }, 1000);
Enter fullscreen mode Exit fullscreen mode

In this example, I've added an event on the open state of collapse and I've used a setTimeout function for simulate Ajax request.

Top comments (0)