Introduction to JQuery Tutorial (iii): selectors

Source: Internet
Author: User
Tags jquery library

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

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 tags

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

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

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

#id Select

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 a button is clicked, only the element with ID test is hidden.

<! DOCTYPE html>
. class Selector

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

<! DOCTYPE html>
More examples

Grammar Description
$ ("*") Select So element
$ (This) Select Current Element
$ ("P.intro") Option P element for all Class=intro
$ ("P:first") Select the first P element
$ ("ul Li:first") Select the first <li> element of the first <ul> element
$ ("ul Li:first-child") Select the first element of each <ul>
$ ("[href]") Select all elements with an HREF
$ ("a[target= ' _blank ')") Select a element for all Target=_blank
$ ("a[target!= ' _blank ')") Select All target! The A element of =_blank
$ (": Button") Select All button elements and elements with input type button
$ ("Tr:even") Select all even rows <tr> elements
$ ("tr:odd") Select all singular lines <tr> elements

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.