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.