[英]Each() div with two classes and add css if this div has children
I do not understand where I'm wrong .... 我不明白我哪里错了....
<div class="gsc-webResult gsc-result">Ciao</div>
<div class="gsc-webResult gsc-result">
<td class="gsc-table-cell-thumbnail gsc-thumbnail">Ciao2</td>
</div>
$(".gsc-webResult .gsc-result").each(function () {
if ($(this).children('td').not('.gsc-table-cell-thumbnail gsc-thumbnail')) {
$(this).css('margin-left', '60px');
}
});
I want to add the ' margin-left
' to div that has tag td
with those classes ( .gsc-table-cell-thumbnail gsc-thumbnail
) as a children 我想向带有这些类的标签
td
div中添加' margin-left
'( .gsc-table-cell-thumbnail gsc-thumbnail
类的.gsc-table-cell-thumbnail gsc-thumbnail
)
link jsfiddle: http://jsfiddle.net/s0b75ekw/ 链接jsfiddle: http : //jsfiddle.net/s0b75ekw/
thanks 谢谢
Quiet messed up code 安静弄乱代码
<div class="gsc-webResult gsc-result">Ciao</div>
<div class="gsc-webResult gsc-result">
<span class="gsc-table-cell-thumbnail gsc-thumbnail">Ciao2</span>
</div>
JS JS
$(".gsc-webResult.gsc-result").each(function () {
// ^ Remove the space from here Otherwise it will be nested classes
// Calculate the number of child this element has with tag td and specified classes.
if ($(this).find('span.gsc-table-cell-thumbnail.gsc-thumbnail').length>0)
{
$(this).css('margin-left', '60px');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.