How to determine the current state of jQuery toggle()

房东的猫 提交于 2019-12-05 17:39:57

you can use $(div).is(':visible')

$('.elem').slideToggle('fast', function() {
    alert($(this).is(':visible'));
});
Abhijeet
var className = $(el).attr("class"); 

Can retrieve current class from there on logic can take over test and modify the element:

  • if(className == "yourCss")
  • el.addClass("YourCSS");
  • el.removeClass("YourCSS");

I still believe jvnill's answer is efficient one, unless one has to test multiple class cases.

toggle(): Just toggle of between hide() and show() for the selected elements, by changing the CSS display property.

Note: As a class is added to the element, class attribute(list) of the element gets appended with it, unless removed by the .removeClass() invocation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!