我正在尝试删除多个div之间的共同类,但仅针对每个div中的第一个p
目标以删除该类名。
这是我的HTML:
<div class="items">
<div class="wrapper">
<div class="thing thing--one">
<h2>This title</h2>
<p class="extended-content">A good act does not wash out the bad, nor a bad act the good. Each should have its own reward. Words are like wind. And now his watch is ended. Bastards are born of passion, aren't they? We don't despise them in Dorne. King in the North.</p>
<p class="extended-content">All men must die. It's ten thousand miles between Kings landing and the wall. A good act does not wash out the bad, nor a bad act the good. Each should have its own reward. The wolf and the lion. All men must die.</p>
</div>
<div class="thing thing--two">
<h2>This title</h2>
<p class="extended-content">A good act does not wash out the bad, nor a bad act the good. Each should have its own reward. Words are like wind. And now his watch is ended. Bastards are born of passion, aren't they? We don't despise them in Dorne. King in the North.</p>
<p class="extended-content">All men must die. It's ten thousand miles between Kings landing and the wall. A good act does not wash out the bad, nor a bad act the good. Each should have its own reward. The wolf and the lion. All men must die.</p>
</div>
<div class="thing thing--three">
<h2>This title</h2>
<p class="extended-content">A good act does not wash out the bad, nor a bad act the good. Each should have its own reward. Words are like wind. And now his watch is ended. Bastards are born of passion, aren't they? We don't despise them in Dorne. King in the North.</p>
<p class="extended-content">All men must die. It's ten thousand miles between Kings landing and the wall. A good act does not wash out the bad, nor a bad act the good. Each should have its own reward. The wolf and the lion. All men must die.</p>
</div>
</div>
</div>
当我执行以下操作时:
$(".thing--one p, .thing--two p, .thing--three p").first().removeClass("extended-content");
它只会从thing--one
类中的第一个p
标签中移除第一个extended-content
类。
因此,目前我已经将其写成以下形式:
$(".thing--one p").first().removeClass("extended-content");
$(".thing--two p").first().removeClass("extended-content");
$(".thing--three p").first().removeClass("extended-content");
这样做虽然可行,但感觉很臃肿,并不是去除这三个div中常见类名的最佳方法。
有什么更语义化的想法吗?