Selector-descendant elements, child elements, neighboring elements, sibling elements

Source: Internet
Author: User

CSS, jquery selector syntax are similar, because of the use of a few, some selectors are often confused or forgotten, so here to understand the record under:

1. Descendant element Selector ( ancestor descendant ), child element selector ( parent > Children)

The same HTML code:

< form >    <  name= "Son">    <fieldset>        <  name= "grandson">    </fieldset  ></form>

Descendant selector: . UL Li , can be selected to get descendants of descendant elements: [ <input name= "Son">, < input name = "grandson" >]

Child element selector: . UL > Li , can get elements: [ <input name= "Son" >]

2. Adjacent element selector ( prev + next ), sibling element ( prev ~ siblings )

The same HTML code

<inputname= "N1" /><label>Name:</label><inputname= "N2" /><inputname= "N3" /><fieldset>    <label>Child Label:</label>    <inputname= "N4" /></fieldset><inputname= "N5" />

Adjacent element selector: label + input will be selected to: n2,n4

Peer element selector: Label ~ Input will be selected to: N2, N3, N4, N5 , we can notice whether the neighbor or the sibling elements, N1 are not selected, you can know that the neighboring, peers are backward selection Select the element.

Selector-descendant elements, child elements, neighboring elements, sibling elements

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.