Home >Web Front-end >JS Tutorial >Analysis of CSS selector usage in Jquery_jquery
The examples in this article describe the usage of CSS selectors in Jquery. Share it with everyone for your reference. The details are as follows:
jQuery uses a set of CSS selectors, there are 5 types in total, namely tag selector, ID selector, class selector, universal selector and group selector, which are described as follows:
1. Tag selector
is used to select existing tag elements in the HTML page, also known as element selector, format: $("element"), such as $("div"), the same as getElementByTagName
2. ID selector
is used to obtain an element with an id attribute. The format is as follows: $("id"), the same as getElementById
3. Class Selector
is used to obtain an element with a class attribute, format: $("class")
Add a border style to this text box. First, use the class attribute to bind the text box
4. Universal selector
The universal selector (*) matches all elements and is mostly used to search contextually, that is, to find all tags in the HTML page, $("*")
5. Group Selector
is also called a multi-element selector, which is used to select the results of all specified selector combinations. The syntax is as follows:
For example:
Comprehensive example:
效果图如下所示:
希望本文所述对大家的jQuery程序设计有所帮助。