Jquery learning-Selector

Source: Internet
Author: User
Document directory
  • Instance
Jquery syntax

The jquery syntax is compiled for the selection of HTML elements. You can perform some operations on the elements.

The basic syntax is:$ (Selector). Action ()

    • Dollar sign defines jquery
    • Selector: "query" and "Search" HTML elements
  • Jquery action () executes operations on Elements
Example

$ (This). Hide ()-hide the current element

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

$ ("P. test"). Hide ()-hide all paragraphs of class = "test"

$ ("# Test"). Hide ()-hide all Id = "test" Elements

Tip: jquery uses a combination of xpath and CSS selector syntax. In the subsequent sections of this tutorial, you will learn more about the selector syntax.

Jquery syntax example
$ (This). Hide ()
Demonstrate the jquery hide () function to hide the current HTML element.
$ ("# Test"). Hide ()
Demonstrate the jquery hide () function to hide the element id = "test.
$ ("P"). Hide ()
Demonstrate the jquery hide () function to hide all <p> elements.
$ (". Test"). Hide ()
Demonstrate the jquery hide () function to hide all the elements of class = "test.
Jquery element Selector

Jquery uses the CSS selector to select HTML elements.

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

$ ("P. Intro") select all <p> elements of class = "Intro.

$ ("P # Demo") Select the first <p> element of ID = "Demo.

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.

Jquery CSS Selector

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");

 

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.