Introduction to the use of Jquery:first selector _jquery

Source: Internet
Author: User
1.: First: Get the initial element
2, example
(1) Source code
First.html:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>:first selector </title>
<script type= "Text/javascript" src= "Jquery-2.0.3.js" ></script>
<style type= "Text/css" >
body{
width:7%;
height:100%;
font-size:24px;
Font-weight:bold;
Background-color: #CCCCFF;
Text-align:center;
}
</style>
<script type= "Text/javascript" >
$ (function () {
Set the background color of the first LI in UL and apply it to: Primary selector
$ ("Li:first"). CSS ("Background-color", "#00DDDD");
Sets the background color of the first Li in ol and applies it to: Primary selector
$ (". Two Li:first"). CSS ("Background-color", "#0000CC");
Sets the font color of the first Li in ol, and applies to: primary Selector
$ (". Two Li:first"). CSS ("Color", "#FFFFFF");
});
</script>

<body>
<div>
<ul class= "One" >
<li> Apple </li>
<li> Pear </li>
<li> Orange </li>
<li> Watermelon </li>
<li> Litchi </li>
<li> Grape </li>
<li> Banana </li>
<li> cantaloupe </li>
</ul>
<ol class= "Two" >
<li> Apple </li>
<li> Pear </li>
<li> Orange </li>
<li> Watermelon </li>
<li> Litchi </li>
<li> Grape </li>
<li> Banana </li>
<li> cantaloupe </li>
</ol>
</div>
</body>

(2) display the results as shown below

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.