jquery: Last selector usage instance _jquery

Source: Internet
Author: User

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

This selector matches the last element in the collection of elements.

Syntax structure:

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

This selector is generally used in conjunction with other selectors, such as class selector and element selector, etc.。 For example:
Copy Code code as follows:
$ ("Li:last"). CSS ("Color", "green")

The above code can set the font color in the last Li element in the set of Li elements to green.
if not used with other selectors, the default state is to use with the * selector, for example $ (": Last") equals $ ("*:last").

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>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("button"). Click (function () {
$ ("Li:last"). CSS ("Color", "green")
})
})
</script>
<body>
<div>
<ul>
<li class= "Zhuanqu" >html zone </li>
<li class= "Zhuanqu" >div+css zone </li>
<li class= "Zhuanqu" >jquery zone </li>
<li class= "Zhuanqu" >javascript zone </li>
</ul>
</div>
<button> Click to view Effect </button>
</body>
[size=2]

The above code code can set the font color of the last Li element in the set of Li elements to green.

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>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("button"). Click (function () {
$ (": Last"). CSS ("Color", "green")
})
})
</script>
<body>
<div>
<ul>
<li class= "Zhuanqu" >html zone </li>
<li class= "Zhuanqu" >div+css zone </li>
<li class= "Zhuanqu" >jquery zone </li>
<li class= "Zhuanqu" >javascript zone </li>
</ul>
<div>
<span> Cloud-dwelling community </span>
</div>
</div>
<button> Click to view Effect </button>
</body>

The font color in the button button is set to green because there is no specified selector to match with the: last selector, so the default is to match with the * selector.

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.