Jquery retrieves objects

Source: Internet
Author: User
1,  Some core methods of jquery  
$ ("Element" ). Length; 'number of elements, which is an attribute $ ( "Element" ). Size (); 'is also the number of elements, but parentheses are a method $ ( "Element" ). Get (); 'a set of elements in the page, stored in arrays $ ( "Element" ). Get (INDEX); 'has the same function as above. index indicates the nth element, and the subscript of the array $ ( "Element" ). Get (). Reverse (); 'to get the direction of the array $ ( "Element1"). Index ($ ("element2" ); 'Element 2's index value in element 1 is...
2 , Basic object acquisition (note that all the objects obtained here are jquery objects instead of DOM objects, but they can be converted)$ ( "*" ) 'Indicates getting all objects, but I have never used it like this $ ( "# XXX") 'Get ID = Element Object of XXX (ID can be the tag ID or CSS style ID) commonly used $ ( "Input [name = 'username']") obtain the name = 'username' in the input tag'Commonly used element objects $ ( ". ABC ")' Get the style class name. ABC element object commonly used $ ("Div ") ' The tag selector Selects all DIV elements commonly used $ ( "# A,. B, span ")' It indicates that the element whose ID is a and that uses Class B and all span elements $ ("# A. B P ") 'Id is a and all P elements in B style are used.

3. Hierarchical Element Acquisition
$("Element1 element2 element3...") 'the front parent level is followed by a subset
$ ("Div> P") 'gets all P elements under the div.
$ ("Div + P") the first P element after the DIV Element
$ ("Div ~ P ") All P elements behind 'div

4. Simple Object acquisition
$ ("Element: First") 'First element of a certain element in the HTML page
$ ("Element: Last") the last element of a certain element in the HTML page
$ ("Element: Not (selector)") 'removes all elements that match the given selector, for example: $ ("input: Not (: checked )") indicates Selecting All unselected check boxes.
$ ("Element: Even") 'returns an even number of rows.
$ ("Element: odd") 'returns an odd number of rows.
$ ("Element: eq (INDEX)") 'gets a given index value
$ ("Element: GT (INDEX)") All elements after obtaining the element of the given index value
$ ("Element: Lt (INDEX)") 'gets all elements before the element with the given index value

5. Get content objects and object visibility
$ ("Element: Contains (text)") 'indicates whether the element contains text content.
$ ('Element: empty ") 'gets
$ ("Element: partnt") 'obtains
$ ("Element: Has (selector)") 'indicates whether an element exists. For example, $ ("P: Has (SPAN)") indicates all P elements containing the span element.
$ ("Element: hidden") 'select all visible elements
$ ("Element: visible") 'select all invisible elements

6. Other Object acquisition methods
$ ("Element [ID]") 'all elements with the ID attribute
$ ("Element [attribute = youlika]" 'obtains all elements whose attributes are youlika.
$ ("Element [attribute! = Youlika] "'Get all elements whose property is not youlika
$ ("Element [attribute ^ = youlika]" 'obtains all elements whose attributes start with not youlika.
$ ("Element [attribute $ = youlika]" 'obtains all elements whose attributes are not the end of youlika.
$ ("Element [attribute * = youlika]" 'obtains all elements whose attributes start with youlika.
$ ("Element [selector1] [selector2] [...] ") 'matches the property selector. For example, $ (" input [ID] [name] [value = youlika] ") indicates that the input element with ID, name, and value is youlika is obtained.

7. Obtain sub-elements
$ ("Element: Nth-child (INDEX)") 'select the nth element under the parent level
$ ("Element: Nth-child (even)") 'select an even number under the parent level
$ ("Element: Nth-child (ODD)") 'select the odd number under the parent level
$ ("Element: Nth-child (3N + 1)") 'expression
$ ("Element: First-Child") 'selects the first child element under the parent level.
$ ("Element: Last-Child") 'selects the last child element under the parent level.
$ ("Element: Only-Child") 'matches a unique child element under the parent level. For example, if dt is unique in the DL list, DT is selected.

8. Get form objects
$ (: Input) // query all input elements, including the drop-down list, text field, single-statement, and check box.
$ (: Text) // match all single-row text boxes
$ (: Password) // match all password boxes
$ (: Radio) // match all radio buttons
$ (: Checkbox) // match all check boxes
$ (: Submit) // match all the submit buttons
$ (: Image) // match all image fields, for example, <input type = "image"/>
$ (: Reset) // match all reset buttons
$ (: Button) // match all buttons
$ (: File) // match all file upload Domains
$ (: Hidden) // matches all the invisible elements or elements whose type is hidden.
$ (: Enabled) // match all available input elements. For example, radio: enabled indicates matching all available single-choice buttons.
$ (: Disabled) // matches all the unavailable input elements, which act in the opposite way.
$ (: Checked) // match all checked check box Elements
$ (: Selected) // match all the drop-down lists

9. Setting and removing element attributes
$ ("Element"). ATTR (name) 'gets the first matching property value, for example, $ ("IMG"). ATTR ("src ")
$ ("Element". ATTR (Key, value) ") 'specifies the attribute of an element.
$ ("Element". ATTR ({key: value, key1: value,...}) 'sets multiple attributes for an element at a time.
$ ("Element"). ATTR (Key, function) 'sets a calculated attribute value for all matching elements.
$ ("Element"). removeattr (name) // remove an attribute

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.