我有这样的DIV结构:
<div id="wire" style="position: absolute">
<div style="position: absolute;background:white" ></div>
<div style="position: absolute;background:red" ></div>
<div style="position: absolute;background:white" ></div>
<div style="position: absolute;background:red" ></div>
<div style="position: absolute;background:white" ></div>
</div>
我能够像这样在jquery中得到所有的孩子:
$("#wire > div")
如何仅使用白色背景获取所有div?
答案 0 :(得分:2)
您可以使用:
$("#wire > div[style*='background:white']")
答案 1 :(得分:1)
嗯......首先你需要删除内联样式。见why。所以你会有这样的事情:
CSS:
/*CSS*/
.absolute {position:absolute;}
.white {background: white;}
.red {background: red;}
HTML:
<!-- HTML -->
<div id="wire" class="absolute">
<div class="white absolute"></div>
<div class="red absolute"></div>
<div class="white absolute"></div>
<div class="red absolute"></div>
<div class="white absolute"></div>
</div>
然后只需这样做:
$('#wire>div.white')
答案 2 :(得分:1)
您也可以使用:
$("#wire > div").filter(function() {
var $this = $(this);
return $this.css("position") == "absolute"
&& $this.css("background-color") == "rgb(255, 255, 255)";
});