jQuery — Toggle to state other than default?
If i use the code:
$('.myDiv').toggle();
With the initial state as:
.mydiv {display:none}
How can I state that the toggle must go to
.mydiv {开发者_Go百科display:table}
?
Currently it just goes to a default block.
Thanks
Use a css class for the display:
.myDiv { display: table; }
.noDisplay { display: none; }
Then use .toggleClass() to toggle the class:
$('.myDiv').toggleClass("noDisplay");
Documentation
You can't use toggle to do that. You will need to actually use .css("display","table")
Kyle's method is probably a bit faster.
精彩评论