Jquery's method of getting objects is adequate for a common variety of objects

  • 2020-03-30 02:56:50
  • OfStack

(1) basic object acquisition

$(" * ")
Get all objects

$(" # element ")
Getting an object with id element is equivalent to document.getelementbyid (" element ");

$(" ABC ")
Gets the object with class ABC

$(" div ")
Gets all the div elements in the HTML

$("#a,.b, p")
Get id a and class b and all the p elements

$(" # a. b p ")
Gets the p element under id a and class under b

(2) hierarchical object acquisition

$(" div> Input ")
Gets all the input objects under div

$(" div + h ")
Gets an h element immediately after the div

$(" div ~ p ")
Gets all the p elements after the element div

(3) simple object acquisition

$(" element: first ")
Gets the first $("div:frist") of an element on the page to denote the first div

$(" element: the last ")
Gets the last element on the page such as $("div:frist") for the last div

$(" element: not selector () ")
Remove all elements that match the selector such as $("input:not(:check)") to indicate all unselected check boxes

$(" element: even ")
Gets the even number of rows of the element element

$(" element: odd ")
Gets the odd row of the element

$(" element: eq (index) ")
Gets the element of a particular index such as $("div:el(2)") for the third div

$(" element: gt (index) ")
Matches all elements greater than the given index value

$(" element: lt (index) ")
Matches all elements less than a given index

$(" : the header ")
The element that matches the h tag

$(" element: animated ")
Matches all elements that are not animated

(4) acquisition of content objects and visibility of objects

$(" Element: the contains (text) ")
Whether the text in the element contains a letter or a string

$(" Element: the empty ")
Gets an element object that contains no text or child elements

$(" Element: the parent ")
Gets that the object element contains text or child elements

$(" Element: from (the selector) ")
Matching whether an element contains an element such as $("p:has(span)") indicates all p elements that contain a span element

$(" Element: hidden ")
Matching all invisible elements, including display:none and the input property is the hidden element

$(" Element: the visible ")
Match all courseware elements

(5) object to obtain advanced order

$(" Element [id] ")
Gets all elements with an id attribute

$(" Element/attribute = the abcd ")
Gets all elements with an attribute of abcd

$(" Element/attribute! = the abcd ")
Gets all elements whose attribute is not abcd

$(" Element/attribute ^ = ab] ")
Gets all elements with an attribute beginning with ab

$(" Element/attribute $= ab ")
Gets all elements whose attributes end in ab

$(" Element/attribute * = ab ")
Gets all elements that have an attribute containing ab

$(" Element [selector1] [selector2] [...]. ")
Matching an attribute selector such as $("input[id][name][value=abcd]") means getting an input element with an id, name, and value as abcd

(6) acquisition of child elements

$(" Element: the NTH - the child (index) ")
Select the NTH child of the parent element, starting at 1
: the NTH - child (even) even
Odd: NTH - child (odd)
: the NTH - child (3 n) expression
: the NTH - child (2) index
: the NTH - child (3 n + 1) expression

$(" Element: first - the child ")
The first child element under the parent level

$(" Element: the last - the child ")
The last child element under the parent level

$(" Element: only - child ")
The only child element under the parent level

(7) get the form object

$(input)
Only the input element of type input button select textarea can be matched

: $(text)
All when line text boxes

$(password)
All password boxes

: $(radio)
All radio buttons

$(: checkbox)
All check boxes

$(: submit)
All submit buttons

$(image)
All image fields
$(reset)
All recharge buttons

$(: the button)
All buttons

$(: file)
All file upload fields

$(hidden)
All invisible or hidden elements

$(enabled)
All available input elements

: $(disabled)
All unavailable input elements

$(checked)
All check box elements

$(selected)
All the drop-down lists

(8) setting and removing of element attributes

$(" Element "). Attr (name)
Gets the attribute value of the first matched element such as $("img").attr(" SRC ");

$(" Element "). Attr ({key: value, the key: value,... })
Set multiple attributes for an element at once

$(" Element "). Attr (key, value)
Sets properties for an element

$(" Element "). Attr (key, the function)
Sets a computed attribute for all matched elements

$(" Element "). RemoveAttr (name)
Removes an attribute

Related articles: