Read the first-child details in sharp jQuery, jqueryfirstchild

Source: Internet
Author: User

Read the first-child details in sharp jQuery, jqueryfirstchild

Today, when I read the book "sharp jQuery", I saw the filtering selector section. I paid attention to a knowledge point.

 

(I don't need the same code in the book as an example) A simple example-code:

1 <ul> 2 <li> first li </li> 3 <li> second li </li> 4 <li> third li </li> 5 <li> fourth li </li> 6 </ul>

If you want the first li color to be blue, the method in the book is $ ("ul: first-child" ).css ("color", "blue ");

(Ps: I used jQuery introduced online: <script src = "http://libs.baidu.com/jquery/1.9.1/jquery.js"> </script>)

At this time, my first response is $ ("ul: first-child"). It's ul, not his son li. I have found an example on the Internet and found that it is generally written in the format of $ ("ul li: first-child ").

Is the writing in the book wrong? I tried it in the editor and found that it was correct. The original key issue was caused by a space behind ul of $ ("ul: first-child! If spaces are removed, ul is selected!

Amount... This details .... It's better to use ul + space in the future, or ul li. This should be done. After all, $ ("ul: first-child") has more li than $ ("ul li: first-child! More demanding conditions! Example

<Ul> <p> lala </p> <li> first li </li> <li> second li </li> <li> third li </li> <li> fourth li </li> </ul>

In the same case, $ ("ul: first-child" ).css ("color", "blue") and $ ("ul li: first-child" ).css ("color ", "blue"), the former lala becomes blue, and the latter has no effect. After all, li is not the first son (not the prince haha ).

First-child and first-of-type, amount. If you see the article you have written, you can find it clearly. The attached address is as follows:

Http://www.cnblogs.com/xuan52rock/p/4416228.html

Well, in simple terms, the former is about the Son, and the latter is about the first thing in this group that is composed of the same element. With the space I mentioned above, we can see it clearly.

Related Article

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.