Basic jquery syntax

Source: Internet
Author: User
JQuery syntax is compiled for the selection of HTML elements. You can perform some operations on the elements. The basic syntax is: $ (selector ). the $ action () symbol defines the jQuery selector to query and find the HTML element jQuery's action () for execution... syntaxHighlight jQuery syntax is compiled for the selection of HTML elements. You can perform some operations on the elements. The basic syntax is: $ (selector ). the $ action () symbol defines the jQuery selector "Query" and "search" the action () of the HTML element jQuery to execute the operation example for the element $ (this ). hide ()-hide the current element $ ("p "). hide ()-hide all paragraphs $ ("p. test "). hide ()-hide all paragraphs of class = "test" $ ("# test "). hide ()-hide all element document readiness functions with id = "test". You may have noticed that all jQuery functions in our instance are in a document ready function: $ (document ). ready (function () {--- jQuery functions go here ----}); this prevents the document from running jQuery code before it is fully loaded (ready. If you run the function before the document is fully loaded, the operation may fail. The following are two examples: Try to hide a nonexistent element to obtain the size of an incomplete loaded image. jQuery element selector jQuery uses the CSS selector to select HTML elements. $ ("P") Select

Element. $ ("P. intro") select all class = "intro"

Element. $ ("P # demo") Select the first id = "demo"

Element. JQuery attribute selector jQuery uses an XPath expression to select an element with a given attribute. $ ("[Href]") selects all elements with the href attribute. $ ("[Href = '#']") select all elements with an href value equal. $ ("[Href! = '#'] ") Select all elements with an href value not equal. $ ("Your href00000000'.jpg ']") select all elements whose href values end with ". jpg. The jQuery CSS selector can be used to change the CSS attributes of HTML elements. The following example changes the background color of all p elements to red: instance $ ("p" ).css ("background-color", "red "); more selector instance syntax descriptions $ (this) Current HTML element $ ("p") All

Element $ ("p. intro") of all class = "intro"

Element $ (". intro ") All class =" intro "elements $ (" # intro ") id =" intro "first element $ (" ul li: first ") each

    The first
  • Element $ ("Your href00000000'.jpg ']") All ". href attribute at the end of jpg "$ (" div # intro. all class = "head" elements in head ") id =" intro"
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.