The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Accordion that opens first heading when any is closed

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #33194


    I would like to find a way for an accordion to always open the first heading if any open heading is closed. For example if heading 3 of 4 is open an the user clicks this heading the #3 accordion boxes closes and the #1 opens.
    Any ideas?


    I haven’t tested this with the extra part your looking to add, but it should at least be in the general area of the solution.

    // Accordion effect
    $('#some-id a').click(function(){

    // Show next element if hidden
    if ($(this).next().is(':hidden')) {
    // Hide all other elements
    $('#some-id a')
    // Element already shown - slide up element, show first
    $('#some-id a')
    return false;

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.