jquery Learning Notes

Source: Internet
Author: User

Note: The following data sources W3School.COM.CN

JQuery syntax

The jQuery syntax is for the selection of HTML elements, and you can perform certain operations on elements.

The underlying syntax is: $ (selector). Action ()

    • Dollar sign ($) defines jQuery
    • Selector (selector) "Query" and "find" HTML elements
    • JQuery Action () performs an operation on an element
    • Example

      $ (this). Hide ()-hides the current element

      $ ("P"). Hide ()-Hides all paragraphs

      $ (". Test"). Hide ()-hides all elements of class= "test"

      $ ("#test"). Hide ()-hides all elements of the id= "test"

    • All jquery functions are in a document ready function (Note: This is to prevent the document from running JQuery code before it is fully loaded (ready). If the function is run before the document is fully loaded, the operation may fail)
JQuery Selector

The JQuery element selector and the property selector allow you to select HTML elements by tag name, property name, or content.

Selectors allow you to manipulate HTML element groups or individual elements.

In the HTML DOM terminology:

Selectors allow you to manipulate a group of DOM elements or a single DOM node.

JQuery element Selector

JQuery uses CSS selectors to select HTML elements.

$ ("P") select the <p> element.

$ ("P.intro") selects all the <p> elements of the class= "Intro".

$ ("P#demo") selects all <p> elements of the id= "demo".

JQuery Property Selector

JQuery uses an XPath expression to select an element with a given property.

$ ("[href]") selects all elements with an href attribute.

$ ("[href= ' # ']") selects all elements with an HREF value equal to "#".

$ ("[href!= ' # ']") selects all elements with an HREF value that is not equal to "#".

$ ("[href$= '. jpg ']") selects all elements with an href value ending with ". jpg".

JQuery CSS Selector

The JQuery CSS selector can be used to change the CSS properties of HTML elements.

The following example changes the background color of all p elements to red:

Instance
$ ("P"). CSS ("Background-color", "Red");

jquery Learning Notes

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.