Basic knowledge of jquery review (base selector, attribute selector, hierarchy selector)

Source: Internet
Author: User

  

1. Base Selector

        

ID Selector: $ ("#id"), style selector: $ (". ClassName"), Element selector: $ ("div"), $ ("*") Select all elements of the page
      
Use both selectors for example: ID and element $ ("#id, div"), where you can add more for example plus a style of $ ("#id, Div,.classname");
    

2. Property Selector

    $ ("Div[title]") Select the div element containing the title, $ ("Div[title]") Select the div element containing the title=test $ ("div[title=test]"); Select the div element with the Title property not equal to test: $ ("div[title!=test]"), which will select the div without the title attribute.
Select the div element that begins with the title TE: $ ("div[title^=te]"), select the div element with title ending in est: $ ("div[title$=est]"), and select the title attribute that contains the div element for es: $ ("div[ Title*=es] ")
  
Multi-Selector Composite use: Select the hidden field, the property containing the title of the Div,id is one,class as one element $ ("Input[type=hidden],div[title, #one,. One]"), so that the object result is a set.

3. Hierarchy Selector

A. Select all the DIV elements under the body

$ ("body div"); Note that this selects all descendant elements under the body, such as any other div in the div that is also selected.

B. Select the sub div under body

$ ("Body>div"); Note that the direct child element of the selected body, that is, the selection does not include the grandchild element Div, the difference is that the angle brackets are added to remove the space.

C. Select the input element next to the Laber element,

$ ("laber+input"); note that when this is selected, two input elements are selected if there are two laber elements in HTLM, and the input element is followed by two laber elements.

D. Selection and all sibling elements behind the form element sibling

$ ("Form~div"), so you select all the DIV elements that follow the same level as the form element.

E. Select all div elements of the same level as the element with ID test

$ ("#test"). Parent (). Children ("div"); Note: First get the element's parent element and then get all the child elements of that element in the DIV element.

      

      

      

    

Basic knowledge of jquery review (base selector, attribute selector, hierarchy selector)

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.