【发布时间】:2013-03-04 08:26:41
【问题描述】:
我的代码正在循环通过一些 div,我试图找到在其样式属性中包含某些文本的那个。这是我最好的尝试,但没有找到。
$("#RootDiv > div").each(function (index)
{
if ($(this).is("[style~='bg-stripes.gif']"))
alert("found");
});
HTML
<div id="RootDiv">
<div style="background-color: White;"></div>
<div style="background-image: url(bg-stripes.gif);"></div>
<div style="background-color: White;"></div></div>
【问题讨论】:
-
HTML 是什么样的?
-
特定文本,或任何文本?
-
你试过
if ($(this).attr('style').indexOf('...') > -1 )吗? -
$(this).is("[style*='bg-stripes.gif']")工作得更好吗?~=按整个单词而不是子字符串查找。 -
@nbrooks 哎呀,添加了。我不擅长 SO。
标签: jquery jquery-selectors attributes