JSFiddle - React, Tailwind, and code Playground
HTML
<!-- FIRST ITEM -->
<div class="accItem" id="web">
<h2>Website Design & Development</h2>
<div class='desc'>
Web Design Web Design Web Design Web Design Web Design Web Design Web Design Web Design Web Design Web Design Web Design Web Design Web Design Web Design
</div>
</div>
<!-- SECOND ITEM -->
<div class="accItem" id="desktop">
<h2>Desktop Software</h2>
<div class='desc'>
Desktop Software Desktop Software Desktop Software Desktop Software Desktop Software Desktop Software Desktop Software Desktop Software Desktop Software Desktop Software Desktop Software Desktop Software
</div>
</div>
<!-- THIRD ITEM -->
<div class="accItem" id="mobile">
<h2>Mobile Software</h2>
<div class='desc'>
Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software Mobile Software
</div>
</div>
<!-- FOURTH ITEM -->
<div class="accItem" id="design">
<h2>Graphic Design & Branding</h2>
<div class='desc'>
Graphic Design & Branding Graphic Design & Branding Graphic Design & Branding Graphic Design & Branding Graphic Design & Branding Graphic Design & Branding Graphic Design & Branding Graphic Design & Branding Graphic Design & Branding Graphic Design & Branding Graphic Design & Branding
</div>
</div>
CSS
body{font:12px verdana; color:#999}
.accItem{
background:url('http://www.jasongoldberg.com/images/disclose.png') no-repeat;
background-color:#efefef;
background-position:0px 6px;
display:none;
border:1px solid #999;
margin: 3px 0px 3px 0px;
}
.accItemSel{
background:url('http://www.jasongoldberg.com/images/disclosed.png') no-repeat;
background-position:0px 6px;
border:1px solid #006;
background-color:#fff;
margin: 3px 0px 3px 0px;
}
.accItem h2{
margin: 5px 0px 5px 0px;
background-position:left top;
padding-left:30px;
color:#666;
font-size:20pt;
cursor:pointer;
}
.accItemSel h2{
margin: 5px 0px 5px 0px;
background:;
background-position:left top;
padding-left:30px;
color:#006;
font-size:20pt;
}
.accItem h2:hover{
color:#600;
}
.accItem .desc, .accItemSel .desc{
display:none;
margin: 5px 0px 5px 20px;
padding: 10px 0px 10px 30px;
}
JavaScript
//jAccordion
(function( $ ){
$.fn.jAccordion = function() {
showItems('');
$(this).find('h2').live('click', function(){
var that=$(this).parent();
$('.accItemSel').addClass('accItem');
$('.accItemSel').removeClass('accItemSel');
$('.accItem .desc:visible').slideUp('slow',function(){
$(that).find('.desc').slideDown('slow');
$(that).removeClass('accItem');
$(that).addClass('accItemSel');
});
});
};
function showItems(def){
if ($('.accItem').not(':visible').length>0){
$($('.accItem').not(':visible')[0]).fadeIn('medium',function(){
showItems(def);
});
}else{
var p = null;
if (def.length>0)
p=$('.accItem#'+def);
else
p=$('.accItem:first');
$(p).addClass('accItemSel');
$(p).removeClass('accItem');
$(p).find('h2').css('background-image', 'none');
$(p).find('.desc').slideDown('fast');
}
}
})( jQuery );
$('.accItem').jAccordion();