Home  >  Article  >  Web Front-end  >  Simple CSS Selector - Regular Selector

Simple CSS Selector - Regular Selector

无忌哥哥
无忌哥哥Original
2018-06-29 15:18:501584browse

Simple CSS selector-regular selector

* There are 5 css conventional selectors

* tag label selector: $('div'), select according to the tag name, Return the collection

* id selector: $('#top'), select according to the element id attribute, return a single

* class selector: $('.active'), select according to the element Class attribute selection, return collection

* * Wildcard selector: $('*'), select all elements, return collection

* Group selector: $('p, h2 , li'), select multiple different elements at the same time and return the collection

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>1简单的CSS选择器-常规选择器</title>
</head>
<body>
<h2>标签选择器</h2>
<h2>标签选择器</h2>
<h2 id="green">id选择器</h2>
<h2>类选择器</h2>
<h2>类选择器</h2>
<p>我是一个段落</p>
<li>我是一个列表项</li>
</body>
</html>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
//1.标签选择器:选择页面中具有相同标签名称的元素,返回集合
$(&#39;h2&#39;).css(&#39;color&#39;, &#39;red&#39;)
//2.id选择器: 根据标签中的id属性来选择元素,返回单个
$(&#39;#green&#39;).css(&#39;color&#39;, &#39;green&#39;)
//3.类选择器: 也叫class选择器,根据标签中的class属性来选择元素,返回集合
$(&#39;.blue&#39;).css(&#39;color&#39;, &#39;blue&#39;)
//4.通配选择器: 选择所有的元素,返回集合
$(&#39;body *&#39;).css(&#39;background-color&#39;, &#39;wheat&#39;)
//5.群组选择: 同时选择多个不同类型的元素,返回集合
$(&#39;h2.blue, p, li&#39;).css(&#39;border&#39;, &#39;2px solid red&#39;)
</script>

The above is the detailed content of Simple CSS Selector - Regular Selector. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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