Determine if the jquery element is hidden

Source: Internet
Author: User

First: Using CSS Properties

Copy CodeThe code is as follows:
var display =$ (' #id '). CSS (' Display ');
if (display = = ' None ') {
Alert ("You found out, I was hidden!") ");
}

The second type: using the jquery built-in selector

Let's say we have this label on our page,

Copy CodeThe code is as follows: <div id= "Test" >
< p> is just for testing </p>
</div>


Then, we can use the following statement to determine whether the tag ID "Test" is hidden:

Copy CodeThe code is as follows: if ($ ("#test"). Is (": hidden")) {...}//provided that the library of jquery has been directed in


In this way, we can easily determine if an element is hidden and animate according to its state, such as:

Copy CodeThe code is as follows:
if ($ ("#test"). Is (": hidden")) {
$ ("#test"). Show (); If the element is hidden, it appears
}else{
$ ("#test"). Hide (); If the element is visible, it is hidden
}

jquery Determines whether the element shows whether it is hidden

Copy CodeThe code is as follows:
var node=$ (' #id ');


The first form of a notation

Copy CodeThe code is as follows:
if (node.is (': Hidden ')) {//If node is hidden, the node element is displayed, otherwise hidden

Node.show ();

}else{

Node.hide ();

}


The second type of notation

Copy CodeThe code is as follows:
if (!node.is (': Visible ')) {//If node is hidden, the node element is displayed, otherwise hidden

Node.show ();

}else{

Node.hide ();

}

if (node.is (': Visible ')) {//Hide the node element if node is displayed, otherwise display

Node.hide ();

}else{

Node.show ();

}

jquery determines whether objects are displayed or hidden

JS Code

Copy CodeThe code is as follows:
JQuery ("#tanchuBg"). CSS ("display")
JQuery ("#tanchuBg"). Is (": visible")
JQuery ("#tanchuBg"). Is (": hidden")

JS Code

Copy CodeThe code is as follows:
$ (Element). Is (": visible")//Checks for Display:[none|block], ignores Visible:[true|false]

JS Code

Copy CodeThe code is as follows:
$ (' Element:hidden ')
$ (' element:visible ')

JS Code

Copy CodeThe code is as follows:
$ (". Item"). each (function ()
{
if ($ (this). CSS ("visibility") = = "hidden")
{
Handle non visible state
}
Else
{
Handle Visible state
}
})

JS Code

Copy CodeThe code is as follows:
AR isVisible = $ (' #myDiv '). Is (': visible ');
var Ishidden = $ (' #myDiv '). Is (': hidden ');

JS Code

Copy CodeThe code is as follows:
if ($ (this). CSS ("display") = = ' None ') {

/* Your code here*/
}
else{

/* Alternate logic */
}

Determine if the jquery element is hidden

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.