For ": Nth-child" preceded by a space to create a distinction between personal understanding __javascript

Source: Internet
Author: User

In learning jquery to the ": Nth-child" selector of the child element filter selector, I found that when using the ": Nth-child" code, the preceding space for the page display will have a different effect, as follows: without spaces:

$ (' Div.one:nth-child (1) '). CSS (' background ', ' Darkgoldenrod ');

Display effect:

When adding spaces:

$ (' Div.one:nth-child (1) '). CSS (' background ', ' Darkgoldenrod ');

Display effect:


The distinction is obvious, so the individual understands:: The Nth-child is preceded by a space because of the logic of the $ (' ancestor descendant ') in the jquery hierarchy selector, that is, after adding a space: Nth-child gets the front ancestor The descendant element of the element descendant. The above example explains:
When: Nth-child is not preceded by a space,: Nth-child is Div.one index to obtain the conditions, so it gets the Div.one element with the index number 1 element. When: Nth-child preceded by a space,: Nth-child is indexed by Div.one's descendant elements, which means that, in the case of a space, the selector chooses the element with the index number 1 under the <div> parent element of class one.


PS: The two great gods in the question area have also helped to answer my questions, and the answer, like my personal understanding, has confirmed my understanding and thanked the following two teachers again:


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.