The role of the $ symbol in jquery

Source: Internet
Author: User
Tags jquery library

The role of the $ symbol in jquery
    1. As a jquery wrapper, use selectors to select DOM elements (this is also the most powerful feature)

      For example: $ ("Table tr:nth-child (even)")

    2. Utility functions, as prefixes of namespaces for several common utility functions

      Example: $.trim (somestring)

    3. The document-ready handler, which is equivalent to $ (documents). Prepare (...)

      For example: $ (function () {...}); The function inside will be executed after the DOM tree has been loaded.

    4. Creating DOM elements

      For example: $ ("<p>how is you?</p>")

    5. Extending jquery

      For example: $.fn.disable = function () {...}

    6. Using jquery and other libraries

      For example: The prototype library is also using the $ sign, JQuery provides noconflict functions to avoid collisions, jquery.noconflict (); restore the $ symbol to the meaning of a non-jQuery library definition

    7. JQuery Selector

Selector
SelectorExample Select
* $("*") All elements
#ID $ ("#lastname") id= elements of "LastName"
. class $ (". Intro") All elements of class= "Intro"
Element $ ("P") All <p> elements
. class. class $ (". Intro.demo") All class= "Intro" and Class= "demo" Elements
: First $ ("P:first") First <p> Element
: Last $ ("P:last") Last <p> Element
: Even $ ("Tr:even") All even <tr> elements
: Odd $ ("tr:odd") All odd <tr> elements
: eq (index) $ ("UL Li:eq (3)") Fourth element in the list (index starting from 0)
: GT (no) $ ("UL li:gt (3)") List elements with index greater than 3
: LT (no) $ ("UL Li:lt (3)") List elements with index less than 3
: Not (selector) $ ("Input:not (: Empty)") All input elements that are not empty
: Header $ (": Header") All heading elements
: Animated All animated elements
: Contains (text) $ (": Contains (' W3school ')") All elements containing the specified string
: Empty $ (": Empty") All elements with No child (element) nodes
: Hidden $ ("P:hidden") All hidden <p> elements
: Visible $ ("table:visible") All the visible tables
S1,s2,s3 $ ("Th,td,.intro") All elements with a matching selection
[attribute] $ ("[href]") All elements with an HREF attribute
[attribute=value] $ ("[href= ' # ']") The value of all href attributes equals "#" elements
[attribute! =value] $ ("[href!= ' # ']") The value of all HREF attributes is not equal to the "#" element
[attribute$=value] $ ("[href$= '. jpg ']") The value of all HREF attributes contains elements ending with ". jpg"
: input $ (": input") All <input> elements
: Text $ (": Text") All <input> elements of type= "text"
:p Assword $ (":p Assword") All <input> elements of type= "password"
: Radio $ (": Radio") All <input> elements of type= "Radio"
: checkbox $ (": checkbox") All <input> elements of the type= "checkbox"
: Submit $ (": Submit") All <input> elements of type= "submit"
: RESET $ (": Reset") All <input> elements of type= "reset"
: button $ (": Button") All <input> elements of type= "button"
: Image $ (": Image") All <input> elements of type= "image"
: File $ (": File") All <input> elements of type= "file"
: Enabled $ (": Enabled") All the active input elements
:d isabled $ (":d isabled") All disabled input elements
: Selected $ (": Selected") All selected input elements
: Checked $ (": Checked") All selected input elements

The role of the $ symbol in jquery

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.