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.标签选择器:选择页面中具有相同标签名称的元素,返回集合 $('h2').css('color', 'red') //2.id选择器: 根据标签中的id属性来选择元素,返回单个 $('#green').css('color', 'green') //3.类选择器: 也叫class选择器,根据标签中的class属性来选择元素,返回集合 $('.blue').css('color', 'blue') //4.通配选择器: 选择所有的元素,返回集合 $('body *').css('background-color', 'wheat') //5.群组选择: 同时选择多个不同类型的元素,返回集合 $('h2.blue, p, li').css('border', '2px solid red') </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!