jquery gets the elements in two ways: the jquery selector, the jquery traversal function.
1. Acquire itself:
A. Only one jquery selector is required
Selector Selector |
Instance |
Description |
#Id |
$ (' #myId ') |
ID selector: Can get to an element with id "myId", Case sensitive |
B. Multiple jquery selector combinations
B1.jquery Selector
Selector Selector |
Instance |
Description |
. class |
$ ('. MyClass ') |
Class selector: You can get all the elements of class ' MyClass ' |
Element |
$ (' P ') |
Get all the <p> elements |
: Header |
$ (': Header ') |
Get all the caption elements: |
: Animated |
$ (': Animated ') |
Get all the animated elements |
: Contains (text) |
$ (' P:contains (Hello) ') |
Gets all the <p> elements that contain text Hello, and the middle text is case-sensitive |
: Hidden |
$ (': Hidden ') |
Get all the hidden elements: width and height of 0, Display:none, Type=hidden, |
[Attribute] |
$ (' [href] ') |
Property selector: Gets all elements that have a property of href |
[Attribute=value] |
$ (' [href=a.html] ') |
= gets all elements with an attribute href and a value of a.html ! = gets all elements with an attribute href, and the value is not equal to a.html $= gets all elements with an attribute href, and the value ends with a.html ^= gets all elements with an attribute href and whose value begins with a.html ~= gets all the elements with the attribute href, and the value contains the word "a.html" *= gets all the elements with the attribute href, and the value contains the text "A.html" |
: input |
$ (': input ') |
Get all input elements |
: Radio |
$ (': Radio ') |
All input elements with type= "Radio" The similarities are: : text,: Chexbox,:p Assword,: Submit,: Reset,: button,: File |
: Enabled |
$ (': Enabled ') |
All of the input elements that are enabled. :d isabled is the opposite. |
: Checked |
$ (': Checked ') |
All selected input selections (radio box, check box) |
: GT (Index) |
$ (' P:gt (2) ') |
Index starting with 0, gets all <p> elements of index greater than (not included) 2 |
: LT (Index) |
$ (' P:lt (2) ') |
Index starting from 0, gets all <p> elements with index less than (not included) 2 |
: Even |
$ (' Tr:even ') |
All even <tr> elements |
: Odd |
$ (' tr:odd ') |
All odd <tr> elements |
B2.jquery selector jquery traversal function Mix
Selector Selector |
Instance |
Description |
: First |
$ (' P:first ') |
First <p> Element |
: Last |
$ (' p:last ') |
Last <p> Element |
: EQ (Index) |
$ ("P:eq (1)") |
Second <p> element, index starting from 0 |
B3.jquery traversal function
Method |
Describe |
EQ () |
Returns the element with the specified index number of the selected element |
First () |
Returns the first element of a selected element |
Last () |
Returns the last element of the selected element |
2. Select sibling elements
jquery Selector
$ (' div + P ') each div adjacent to the next <p> element
$ (' div ~ p ') gets all the <p> elements in the div sibling
jquery traversal function
Next () returns the last sibling element of the selected element
Nextall () returns all sibling elements after the selected element
Prev () returns the previous sibling element of the selected element
Prevall () returns all sibling elements before the selected element
3. Get the parent element
jquery Selector
$ ("p:parent") gets the parent element of all P-elements
jquery traversal function
Parent () Gets the element of the selected element
Parents () gets all the ancestor elements of the selected element
4. Get child elements
jquery Selector
$ (' div > P ') gets all the <p> elements of the div direct child element
$ (' div p ') gets the <p> element for all descendants of Div
jquery traversal function
Children () returns all the immediate child elements of the selected element
Contents () Returns all immediate child elements (containing text and comment nodes) of the selected element
Find () returns the descendant elements of the selected element
jquery Gets the element method