jquery: Visible Selector Usage instance _jquery

Source: Internet
Author: User

The example in this article describes jquery: visible selector usage. Share to everyone for your reference. The specific analysis is as follows:

This selector can match all currently visible elements.

Syntax structure:

Copy Code code as follows:
$ (": visible")

This selector is typically used in conjunction with other selectors, such as the class selector and the element selector, and so on. For example:

Copy Code code as follows:
$ ("div:visible"). CSS ({color: "Blue"})

The above code can set the font color in the visible div element to blue.
if not used with other selectors, the default state is to use with the * selector, for example $ (": visible") is equivalent to $ ("*:visible").

Instance code:

Example one:

Copy Code code as follows:

<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title> Cloud-dwelling community </title>
<style type= "Text/css" >
. Display{display:none;}
</style>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("button"). Click (function () {
$ ("div:visible"). CSS ({color: "blue"});
})
})
</script>
<body>
<div class= "Display" > I am invisible </div>
<div> I was visible </div>
<ul>
<li> Cloud-dwelling communities welcome you </li>
</ul>
<button> Click to view Effect </button>
</body>

The code above can set the text color in the visible div to blue.

Example two:

Copy Code code as follows:

<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title> Cloud-dwelling community </title>
<style type= "Text/css" >
. display {
Display:none;
}
</style>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("button"). Click (function () {
$ (": Visible"). CSS ({color: "blue"});
})
})
</script>
<body>
<div class= "Display" > I am invisible </div>
<div> I was visible </div>
<ul>
<li> Cloud-dwelling communities welcome you </li>
</ul>
<button> Click to view Effect </button>
</body>

Since the above code does not specify a selector to be used in conjunction with the: visible selector, the default and * selector are used, so the code can set the text color in all visible elements to blue.

I hope this article will help you with your jquery programming.

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.