javascript - Having the first child open in accordion -


i have code:

<div class="accordionbutton">     <span>accordion button</span><span class="plusminus">+</span> </div>     <div class="accordioncontent">         <p>stuff in accordion</p>     </div>  <div class="accordionbutton">     <span>accordion button</span><span class="plusminus">+</span> </div>     <div class="accordioncontent">         <p>stuff in accordion</p>     </div> 

and want first tab accordioncontent box open when page visited. when clicking others, it'll slide , open other content. how can modify code first accorioncontent box open?

javascript:

$(document).ready(function() {     $('.accordionbutton').click(function() {         $('.accordionbutton').removeclass('on');         $('.accordioncontent').slideup('normal');         $('.plusminus').text('+');         if($(this).next().is(':hidden') == true) {             $(this).addclass('on');             $(this).next().slidedown('normal');             $(this).children('.plusminus').text('-');          }       });     $('.accordionbutton').mouseover(function() {         $(this).addclass('over');     }).mouseout(function() {         $(this).removeclass('over');     });     $('.accordioncontent').hide();  }); 

i tried

.accordioncontent:first-child{   display:block; } 

but doesn't work. suggestions?

http://jsfiddle.net/na5fy/110/

or try adding this

$(".accordioncontent").first().show(); 

after

$(".accordioncontent").hide(); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -