我不明白我在哪里错....
<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');
}
});
我想将'
margin-left
'添加到具有标签td
的div中,并将这些类(.gsc-table-cell-thumbnail gsc-thumbnail
)作为子级链接jsfiddle:
http://jsfiddle.net/s0b75ekw/
谢谢
最佳答案
安静弄乱代码
<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
$(".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');
}
});