Jquery object Retrieval

Source: Internet
Author: User
Some of JQuery's core methods $ (& quot; Element & quot ;). length; & amp; lsquo; number of elements, which is an attribute $ (& quot; Element & quot ;). size (); & amp; rsquo; is also the number of elements, but brackets are a method $ (& quot; Element & quot ;). get (); & amp; lsq

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 collection of elements on the page, stored in Arrays
$ ("Element"). get (index); 'is the same as above. index indicates the elements and subscript of the array.
$ ("Element"). get (). reverse (); 'indicates the direction of the obtained array.
$ ("Element1"). index ($ ("Element2"); 'the index value of element 2 in element 1 is...

, Basic object acquisition
(Note that all Jquery objects are obtained here instead of Dom objects, but they can be converted)
$ ("*") 'Indicates getting all objects, but I have never used it like this.
$ ("# XXX") 'obtain the Element Object id = XXX (id can be the tag id or CSS style id)
$ ("Input [name = 'username']") obtain the Element Object name = 'username' in the input tag.
$ (". Abc") 'to obtain the style class name is. abc element object commonly used
$ ("Div") 'tag selector Selects all div elements commonly used
$ ("# A,. B, span") 'indicates the element whose ID is a, the element that uses Class B, and all span elements.
$ ("# A. B p") 'id is a and all p elements in the B style are used.

, 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

, 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 of the given index value

, Content Object acquisition 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

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.
, Sub-element acquisition

$ ("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.
, Form object acquisition

$ (: 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 domains, such
$ (: 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
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 a genus

Related Article

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.