jquery - How to get accordion menu closed by default on load -
i have jquery code make lists act accordion. accordion open on page load. can please tell me how close on page load?
$(document).ready(function () { $('#nav > li > a').click(function() { if ($(this).attr('class') != 'active') { $('#nav li ul').slideup(); $(this).next().slidetoggle(); $('#nav li a').removeclass('active'); $(this).addclass('active'); } }); });
please tell me how edit keep accordion closed on page load.
i dont know html code is, if want hide accordion content, think can $(window).load(function() {});
- when document has finished loading, can hide accordion content
hide()
, orslideup()
or whatever function (or maybe when dom ready?) - (or if possible. throw in css hide it, though didn't ask it, i'm throwing out there sake of it)
check out here or snippet bellow:
$(document).ready(function() { $('#nav > li > a').click(function() { if ($(this).attr('class') != 'active') { $('#nav li ul').slideup(); $(this).next().slidetoggle(); $('#nav li a').removeclass('active'); $(this).addclass('active'); } }); }); $(window).load(function() { //when document finished loading, hide it; or maybe place on dom ready function? $('#nav li ul').hide(); });
/* #nav li ul{ display: none } */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <ul id="nav"> <li> <a href="#">some accordion title guess</a> <ul> <li>some accordion content</li> <li>some accordion content</li> <li>some accordion content</li> <li>some accordion content</li> <li>some accordion content</li> </ul> </li> </ul>
Comments
Post a Comment