Skip to content

Instantly share code, notes, and snippets.

@ataylorme
Created November 17, 2012 23:17
Show Gist options
  • Save ataylorme/4101294 to your computer and use it in GitHub Desktop.
Save ataylorme/4101294 to your computer and use it in GitHub Desktop.
Simple jQuery accordion
var headings = $('h3'),
paras = $('p');
paras.hide().eq(0).show();
headings.click(function() {
var cur = $(this); //save the element that has been clicked for easy referal
cur.siblings('p').slideUp(); //hide all the paragraphs
cur.next('p').slideDown(); //get the next paragraph after the clicked header and show it
})​;​
@ataylorme
Copy link
Author

A very simple jQuery accordion. I recommend using more specific targets than h3 and paragraph tags. Fiddle is here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment