When the sidebar is closed, the jQuery Accordion tab should also close automatically

I have a sidebar that opens when the plus icon is clicked. Inside the sidebar, there is an accordion that can be opened independently. Even when the sidebar is closed, the accordion remains open.

Is it possible to automatically close the accordion when the sidebar is closed?

Please refer to the following code: https://jsfiddle.net/bob_js/kefq1bxo/

HTML:

<div class="container">
  <i class="glyphicon glyphicon-plus-sign cd-btn"></i>
</div>

<div class="cd-panel from-right"> 
    <header class="cd-panel-header">
        <a href="#0" class="cd-panel-close"></a>
    </header>
    <div class="cd-panel-container">
        Content
        <div class="nav-accord2">
            <div id="accordion">
                <h3 >Header</h3>
                <div>Text 1</div>
            </div>
        </div>
    </div>

jQuery:

$(".glyphicon-minus-sign, .glyphicon-plus-sign").click(function(){
    $(this).toggleClass("glyphicon-minus-sign glyphicon-plus-sign");
});

jQuery(function($){
    //open the lateral panel
    $('.cd-btn').on('click', function(event){
        event.preventDefault();
        $('.cd-panel').toggleClass('is-visible');
        // CHECKING ICON OF .cd-btn-a
        if($('.cd-btn-a').hasClass('glyphicon-minus-sign')) {
            $('.cd-btn-a').toggleClass('glyphicon-minus-sign glyphicon-plus-sign');
            $('.cd-panel-a').removeClass('is-visible');
        }
    });
    //close the lateral panel
    $('.cd-panel').on('click', function(event){
        if( $(event.target).is('.cd-panel') || $(event.target).is('.cd-panel-close') ) { 
            $('.cd-panel').removeClass('is-visible');
            $('.cd-btn').toggleClass("glyphicon-minus-sign glyphicon-plus-sign");
            event.preventDefault();
        }
    });
});

$(function() {
    var icons = {
        header: "ui-icon-caret-1-s",
        activeHeader: "ui-icon-caret-1-n"
    };
    $("#accordion").accordion({
        icons: icons
    });
    $("#toggle").button().on("click", function() {
        if ($("#accordion").accordion("option", "icons")) {
            $("#accordion").accordion("option", "icons", null);
        } else {
            $("#accordion").accordion("option", "icons", icons);
        }
    });
});
$("#accordion").accordion({ header: "h3", collapsible: true, active: false, heightStyle: "content"});

Answer №1

To accomplish this task, you should utilize

$( "#accordion" ).accordion('option', {active: false});

Example Link

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The jQuery mobile button may occasionally appear selected without triggering a page transition

When using a Phonegap Application with jQuery mobile, I have encountered an issue where clicking a button sometimes only selects it and does not transition to the next page. This even happens with the back buttons generated automatically by the library, re ...

Modify dates on constant URL and run the link

I've got a link that looks like this: Is it possible to create an HTML form with two input date fields and merge them into a single link similar to the one above? I want to select dateFrom and dateTo separately, then click GO to access the link. I&a ...

When the pop-up remains open between button presses, the Javascript window[] variable is undefined

Here is an example code snippet that utilizes Javascript to open a pop-up window: If the pop-up is closed before pressing another button, the data is successfully sent and can be accessed inside the pop-up's javascript code using the following syntax ...

Two separate functions combined into a single onSubmit event

I am currently working on making two functions operate with just one onsubmit function. Here is the code I have created: onsubmit="return validateForm1(); return validateForm2()"> The issue I am encountering is that only the validateForm1() function s ...

Guide on implementing ng-options and ng-init functionalities in AngularJS

I need help with displaying the ProjectID's in a drop-down list format where users can select one value. Can you provide an example on how to achieve this? [ { "ProjectManagerID": 4, "ProjectID": 4, "ResourceID": 4, "Deleted": false ...

Meteor push/browserhistory fails to navigate or refresh to a different page

Currently, I am attempting to set it up so that when a user clicks on a profile, they are redirected to the profile page of the user they clicked on. Here is the code I am using: const self = this; browserHistory.push({ pathname: '/user ...

Troubleshooting problems with Bootstrap's accordion feature

I've found myself in a tricky situation. I have a set of accordion groups and I need to open them based on certain logic. Additionally, I must be able to have two tabs open simultaneously. The initial tab should also be open when the page loads. I&apo ...

Utilizing graphics within the Atom text editor

Hey, I have a bit of a silly question. I can't seem to figure out why these images aren't showing up on my Atom editor. Can anyone help me with this? <body> <div class="top-container"> <img src="images/clou ...

Properly handling curves in THREE.JS to ensure efficient disposal

I am facing a challenge with managing memory in my project. I have a dynamic sphere with moving points on it, and I am creating curves to connect these points. Here is an illustration of the process: https://i.sstatic.net/PGWuU.jpg As the points are cons ...

What could be causing my Mocha reporter to duplicate test reports?

I've created a custom reporter called doc-output.js based on the doc reporter. /** * Module dependencies. */ var Base = require('./base') , utils = require('../utils'); /** * Expose `Doc`. */ exports = module.exports = ...

Warning in Next.js: Each element in a list requires a distinct "key" property

Currently, I am in the process of building an e-commerce platform using Nextjs. My current focus is on enhancing the functionality of the myCart page, which serves as a dashboard for displaying the list of items that have been ordered. Below is the code s ...

Executing an action using onclick in JavaScript within a Ruby on Rails environment

I am looking to execute a specific action in the controllers/static_pages_controller.rb file: def fileopen my_file = File.new("public/CHNAME1.txt","w") my_file.write "\tfasf" my_file.close end (I have tested this functi ...

What is the name of the event triggered when a jQuery UI draggable element is reverting back to its original position?

I am currently using jQuery UI to create a draggable element on my website. I have added a function to the drag event that continuously tracks the position of the element while the user is dragging it. Additionally, I have set revert: true on this element ...

What is the best way to incorporate an "authorization" validation in certain NodeJs APIs?

In my project using react and node, I create all my react components in a dist/ directory. After uploading this directory to the server, I serve it through nodeJS using the express.static() method. server.use(express.static(__dirname + '/dist' ...

Issues with implementing Callouts CSS in Highcharts are causing complications

Currently, I am attempting to construct a callout, and I aim to format the callouts using CSS. Unfortunately, the CSS implementation seems to be malfunctioning for some unknown reason. Below is the HTML: <script src="https://code.highcharts.com/highch ...

Display the onclick event of multiple buttons on a web page

I am currently working on extracting the "onclick" attribute (onclick="openDirection( 41.051777,28.986551)") from the first button element within each li element. My goal is to display all of the coordinates. In the provided code snippet, I have been abl ...

Customizing Bullet Points in CSS Styling

In an attempt to replicate a specific style in my <ul>, I have utilized the CSS property list-style-image. However, I am facing difficulties aligning the text after the image. How can I achieve this desired alignment? You can view the current output ...

Using Angular's ng-repeat to iterate through an array and display its objects within another array

One of my tasks involves retrieving json objects through a simple post method. The json contains multiple campaigns, organized in an array structure. Each campaign holds slots, which are also arrays with one or more base_image elements. My goal is to di ...

How can I determine the version of gulp that is currently installed on my system?

How can I verify the gulp version currently installed on my system and determine the latest version available on the website? Despite my extensive online search and browsing through the official gulp site, I am unable to locate the specific version infor ...

Troubleshooting a Problem with AngularJS $.ajax

Oops! Looks like there's an issue with the XMLHttpRequest. The URL is returning a preflight error with HTTP status code 404. I encountered this error message. Any thoughts on how to resolve it? var settings = { "async": true, "crossDomain": ...