Multiple methods for jquery to determine whether an element is hidden _ jquery

Source: Internet
Author: User
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 */
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.