开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜