Skip to content

Instantly share code, notes, and snippets.

@thirdj
Created August 16, 2013 05:28
Show Gist options
  • Select an option

  • Save thirdj/6247530 to your computer and use it in GitHub Desktop.

Select an option

Save thirdj/6247530 to your computer and use it in GitHub Desktop.
jquery accordion
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<style>
dl {}
dd { margin: 0; padding: 0.5em 0; padding-left: 10px; }
dt {
cursor: pointer; font-weight: bold; line-height: 2em; background: #F2F2F2;
border-bottom: 1px solid #c5c5c5; border-top: 1px solid #fff; padding-left: 10px;
}
dt:first-child { border-top: none; }
dt:last-child { border-bottom: none; }
.hide { display: none; }
</style>
</head>
<body>
<dl>
<dt>R</dt>
<dd>2222</dd>
<dt>3333</dt>
<dd>4444</dd>
<dt>5555</dt>
<dd>6666</dd>
</dl>
<script>
$(function(){
$('dd').addClass('hide');
$('dl').on('click','dt',function(){
if($(this).next().css('display') == 'block'){
$(this).next().slideUp(200);
return false;
}
$(this).next().slideDown(200).siblings('dd').slideUp(200);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment