开发者

jQuery — Toggle to state other than default?

开发者 https://www.devze.com 2023-04-10 18:55 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号