【发布时间】:2016-11-13 09:31:00
【问题描述】:
这是我的 HTML 代码
<ul id="components">
<li>Computer</li>
<li>Mouse</li>
<li>Keyboard</li>
<li>Printer</li>
<li>CPU</li>
</ul>
#components li:first-child{
color:red;
}
#components li: nth-child(2){
color:blue;
}
#components li: nth-child(3){
color:red;
}
#components li: nth-child(4){
color:red;
}
#components li: nth-child(5){
color:green;
}
我需要的是一个jQuery函数,它可以找到red颜色中的所有li元素,并且可以将背景转换为黄色
我的意思是像
$("#components").find(li elements in red color).css("backgound","yellow");
// find li elements in red color and change the background to yellow
【问题讨论】:
-
改用类和css规则。样式是如何设置的?
标签: javascript jquery html css colors