Jquery best way to initiate toggle on page load
so I am have some divs set up with a toggle function, and I want the first to be toggled visible on page load, what is the be开发者_如何学Cst way to do this? Thanks
$('.paneltop').click( function(){
$(this).next('div').animate(
{'height':"toggle"});
$(this).toggleClass('openpane')
You can use jQuery.toggle
along with .ready()
.
It should look like this:
$(document).ready(function(){
$(".paneltop").next("div").toggle();
});
Note: if you want it to be open, you can use .show()
instead of .toggle()
.
jQuery.toggle - http://api.jquery.com/toggle/
精彩评论