Bourbon accordion click once expand/collapse when clicked

Antony Moss

Hello I'm new here and I wondered if anyone could help. I have implemented bourbon.io's accordion, but I can not get it to open and collapse on a single click.

It opens, but then stays open.

$('.js-accordion-trigger').bind('click', function(e){
  jQuery(this).parent().find('.submenu').slideToggle('fast');  // apply the toggle to the ul
  jQuery(this).parent().toggleClass('is-expanded');
  e.preventDefault();
});

JSFiddle Demo

Reborn

See below if that is what you wanted

$('.js-accordion-trigger').on('click', function(e) {
  $('ul.submenu').not($(this).parent().find('ul.submenu')).slideUp('fast');
  $(this).parent().find('.submenu').toggleClass('is-expanded').slideToggle('fast');
  e.preventDefault();
});
ul.submenu {
  display: none;
}

.is-expanded {
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="accordion">
  <li>
    <a href="javascript:void(0)" class="js-accordion-trigger">Accordion Item</a>
    <ul class="submenu">
      <li>
        <a href="javascript:void(0)">Sub Item 1</a>
      </li>
      <li>
        <a href="javascript:void(0)">Sub Item 2</a>
      </li>
    </ul>
  </li>
  <li>
    <a href="javascript:void(0)" class="js-accordion-trigger">Another Item</a>
    <ul class="submenu">
      <li>
        <a href="javascript:void(0)">Sub Item 1</a>
      </li>
      <li>
        <a href="javascript:void(0)">Sub Item 2</a>
      </li>
    </ul>
  </li>
</ul>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Only open accordion once, but still call onclick each time, when button clicked in jquery

Open accordion when clicked in the URL

Accordion bounces to left when clicked

Accordion header not working when clicked

Open JQuery accordion when link with an id of element within the accordion is clicked

Close the last accordion item when clicked on it in react-accessible-accordion

Accordion that closes when another tab is clicked

Changing accordion arrow direction when clicked

jquery accordion jump when clicked with HASH sigh

Accordion header refreshes page when clicked

Close FAQ accordion when same question is clicked

Display jQuery Accordion when link is clicked?

Open Jquery accordion will not close when clicked

How to get VBA to run through the click of a link or once clicked in Outlook email when someone else recieves the email?

Clicked accordion not expanding when clicked with React's useState

Remove active accordion when click on another accordion in JavaScript

How to close previous accordion when i click on next item in accordion?

Offset on JQuery accordion content when click on accordion header

Accordion is not working when I click the button

Ngb-accordion expand when click on row

ngx-bootstrap-accordion hide/show when button is clicked

Stop opening of Bootstrap Accordion when textbox is clicked using a listener function

Stop expanding/collapse of accordion when cancel to delete icon is clicked

Stop accordion from expanding when More button is clicked

How to.close accordion when clicked for the second time?

show/hide accordion content when icon icon inside <a> is clicked

accordion collapse change background color when clicked (collapsed)

Why is my accordion not showing the sub tabs when it is clicked on?

Accordion Revert to Default Tab Text When Active Tab is Clicked