Getting Started with jquery (3) selectors

Source: Internet
Author: User

The jquery Selector is a very important part of the jquery library.

The jquery Selector is used to select an HTML element whose base statement is the same as the CSS selector (Selector), and all jquery Selector begin with $ ().

Select HTML tag

The way to select an HTML element is to use the tag name of the element directly, such as selecting all <p> elements

$ ("P")

The following example hides all <p> elements when the user clicks a button

$ (document). Ready (function () {     
   $ ("button"). Click (function () {     
     $ ("P"). Hide ();     
   });     
 

#id selection

The JQuery #id selector is used to select the element that defines the id attribute, and the ID of the element on the page should be guaranteed to be unique, and you can use the ID to select a single unique element.

For example, when the button is clicked, only the element with the ID test is hidden.

<! DOCTYPE html>     

. class Selector

The jQuery. Class selector selects all elements that define the class attribute as a value, such as the following example to hide elements with the class name test:

<! DOCTYPE html>  

   

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.