How do I determine the state of a toggled element?

jQuery

How do I determine the state of a toggled element?

You can determine whether an element is collapsed or not by using the :visible and :hidden selectors.

1
2
3
                          
var isVisible = $("#myDiv").is(":visible");
var isHidden = $("#myDiv").is(":hidden");

If you're simply acting on an element based on its visibility, just include ":visible" or ":hidden" in the selector expression. For example:

1
2
3
                          
$("#myDiv:visible").animate({
left: "+=200px"
}, "slow" );