This article mainly introduces multiple methods for jquery to determine whether elements are hidden. This article summarizes multiple examples of methods for determining whether elements are hidden. For more information, see
First: Use CSS attributes
The Code is as follows:
Var display variables ('your id'}.css ('display ');
If (display = 'None '){
Alert ("you have discovered it. I am hiding it! ");
}
Type 2: Use the jquery built-in Selector
Suppose our page has such a tag,
The Code is as follows:
Used only for testing
Then, we can use the following statement to determine whether the tag with id "test" is hidden:
The Code is as follows:
If ($ ("# test"). is (": hidden") {...} // The premise is that the jQuery library has been imported
In this way, we can easily determine whether an element is hidden and set an animation based on its state, for example:
The Code is as follows:
If ($ ("# test"). is (": hidden ")){
$ ("# Test"). show (); // If the element is hidden, it is displayed
} Else {
$ ("# Test"). hide (); // hide an element if it is displayed
}
JQuery checks whether the element is hidden or not.
The Code is as follows:
Var node = $ ('# id ');
First Writing Method
The Code is as follows:
If (node. is (': Den den') {// if node is hidden, the node element is displayed. Otherwise, the node element is hidden.
Node. show ();
} Else {
Node. hide ();
}
Method 2
The Code is as follows:
If (! Node. is (': visable') {// If the node is hidden, the node element is displayed. Otherwise, the node element is hidden.
Node. show ();
} Else {
Node. hide ();
}
If (node. is (': visable') {// if node is displayed, the node element is hidden. Otherwise
Node. hide ();
} Else {
Node. show ();
}
JQuery checks whether an object is displayed or hidden.
Js Code
The Code is as follows:
// JQuery ("# tanchuBg" ).css ("display ")
// JQuery ("# tanchuBg"). is (": visible ")
// JQuery ("# tanchuBg"). is (": hidden ")
Js Code
The Code is as follows:
$ (Element). is (": visible") // Checks for display: [none | block], ignores visible: [true | false]
Js Code
The Code is as follows:
$ ('Element: Den den ')
$ ('Element: visable ')
Js Code
The Code is as follows:
$ (". Item"). each (function ()
{
If (((this).css ("visibility") = "hidden ")
{
// Handle non visible state
}
Else
{
// Handle visible state
}
})
Js Code
The Code is as follows:
Ar isVisible = $ ('# myDiv'). is (': visible ');
Var isHidden = $ ('# myDiv'). is (': Den den ');
Js Code
The Code is as follows:
If (outputs (this).css ("display") = 'None '){
/* Your code here */
}
Else {
/* Alternate logic */
}