How to write jquery selector

(*-*)浩
Release: 2019-05-22 20:39:56
Original
2227 people have browsed it

jquery is a Js framework that simplifies many js writing methods, making it simpler and more efficient. So, how to write jquery selectors? Here are several commonly used selectors for your reference.

How to write jquery selector

jQuery Selectors

jQuery selectors allow you to operate on groups of HTML elements or on individual elements.

jQuery selectors "find" (or select) HTML elements based on the element's id, class, type, attributes, attribute values, etc. It is based on existing CSS selectors, in addition to some custom selectors.

All selectors in jQuery begin with a dollar sign: $().

Element Selector

jQuery element selector selects elements based on their name.

Select all

elements in the page:

$("p")
Copy after login

Example

After the user clicks the button, all

elements are hidden:

         元素选择器
         

这是一个标题

这是一个段落。

这是另一个段落。

Copy after login

#id selector

jQuery #id selector selects the specified element through the id attribute of the HTML element.

The id of the element in the page should be unique, so if you want to select the only element in the page, you need to use the #id selector.

The syntax for selecting elements by id is as follows:

$("#test")
Copy after login

Example

When the user clicks the button, the element with the id="test" attribute will be hidden:

         #id 选择器
         

这是一个标题

这是一个段落

这是另外一个段落

Copy after login

.class Selector

jQuery class selector can find elements by specifying class.

The syntax is as follows:

$(".test")
Copy after login

Instance

After the user clicks the button, all elements with the class="test" attribute are hidden:

         .class 选择器
         

这是一个标题

这是一个段落。

这是另外一个段落。

Copy after login

The above is the detailed content of How to write jquery selector. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!