The basic selector of the jquery selector and the hierarchy selector _jquery

Source: Internet
Author: User
Tags prev tag name

Basic Selector

The base selector is the most commonly used selector in jquery and the simplest selector, which looks for DOM elements by element ID, class, and tag name. In a Web page, each ID name can only be used once, and class allows reuse.

Selector Describe Return Example
#id Matches an element based on the given ID A single element $ ("#test") select an element with the ID test
. class Matches the element based on the given class name Collection elements $ (". Test") Select all elements with test class
Element Matches an element based on the given element name Collection elements $ ("P") Select all <p> elements
* Match all of the elements Collection elements $ ("*") Select all elements
Selector1,selector2,... Selectorn The elements that match each selector are merged and returned together Collection elements $ ("Div,span,p.myclass") Select a set of elements for all <div>,<span> and owning <p> labels with class MyClass

Hierarchy Selector

A hierarchy selector is a good choice if you want to get a specific element, such as descendant elements, child elements, neighboring elements, and sibling elements, through a hierarchical relationship between DOM elements.

Selector Describe Return Example
$ ("ancestor descendant") Select all of the elements in the ancestor
Descendant (descendant) element
Collection elements $ ("div span") Select <div>
All <span> elements
$ ("Parent>child") Select the child element under the parent element,
differs from $ ("ancestor descendant"),
$ ("ancestor descendant") selects descendant elements
Collection elements $ ("Div>span") Select <div> element below
Element name is a child element of <span>
$ ("Prev+next") Select immediately after the Prev element
The next element
Collection elements $ (". One+div") Select Class as one
Next <div> sibling elements
$ ("prev~siblings") Select all after the prev element
Siblings element
Collection elements $ ("#two ~div") select two with ID
All <div> sibling elements behind the element

The equivalence relationship between $ ("Prev+next") selector and Next () method

Selector Method
Equivalence relation $ (". One+div") $ (". One"). Next ("div")

$ ("prev~siblings") the equivalence relation between the selector and the Nextall () method

Selector Method
Equivalence relation $ ("Prev~div")
$ ("#prev"). Nextall ("div")

The above is the entire content of this article, I hope you can enjoy

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.