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:
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.