A_funs
A_funs

Reputation: 1246

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 best way to do this? Thanks

$('.paneltop').click( function(){
    $(this).next('div').animate(
    {'height':"toggle"});
    $(this).toggleClass('openpane')     

Upvotes: 0

Views: 3792

Answers (1)

dvir
dvir

Reputation: 5115

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/

Upvotes: 1

Related Questions