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