In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge that jquery can only use id selector, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe that you can only use id selector for reference after reading this jquery. Let's take a look at it.
Jquery doesn't have to use id selectors only. Jquery provides a variety of selectors: 1, class selector, you can specify class to find elements; 2, tag selector, you can select elements through html signature; 3, attribute selector, using XPath expressions to select elements with specified attributes; 4, group selector, and so on.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
Can jquery only use the id selector?
The jQuery selector allows you to manipulate groups of HTML elements or individual elements.
The jQuery selector "finds" (or selects) HTML elements based on the element's id, class, type, attribute, attribute value, and so on. It is based on the existing CSS selector, in addition to it, it has some custom selectors.
All selectors in jQuery begin with the dollar sign: $().
JQuery element selector
JQuery uses the CSS selector to select the HTML element.
$("p") Select
element.
$("p.intro") select all class= "intro"
element.
$("p#demo") select all id= "demo"
element.
JQuery property Selector
JQuery uses XPath expressions to select elements with a given attribute.
$("[href]") selects all elements with the href attribute.
$("[href='#']") selects all elements with a href value equal to "#".
Select all elements with href values that are not equal to "#".
$("[href$='.jpg']") selects all elements whose href values end with ".jpg".
# id selector
The jQuery # id selector selects the specified element through the id attribute of the HTML element.
The id of the elements in the page should be unique, so you need to use the # id selector to select the unique elements in the page.
The syntax for selecting an element through id is as follows:
$("# test")
Examples are as follows:
(document) .ready (function () {$("button") .click (function () {$("# test") .hide ();}); this is a title
This is a paragraph.
This is another paragraph.
Click me.
Output result:
.class selector
The jQuery class selector can find elements through the specified class.
The syntax is as follows:
$(".test")
Examples are as follows:
$(document) .ready (function () {$("button") .click (function () {$(".test"). Hide ();}); this is a title and this is a paragraph.
This is another paragraph.
Click me.
Output result:
Group selector
Group selector, which is used to perform the same operation on several selectors at the same time.
Syntax:
$("selector 1, selector 2,..., selector n")
The two selectors must be separated by an English comma, otherwise the selector will not work.
Give an example
Css ("color", "red"); css ("color", "red")
Chinese website
This is the end of the article on "whether jquery can only use id selectors". Thank you for reading! I believe you all have a certain understanding of "whether jquery can only use id selectors". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.