我有这个HTML:
<div class="notifications_list">
<div class="title">today <span>+84</span> <i class="fa fa-chevron-down"></i> </div>
<ul>
<li>notification 1</li>
<li>notification 2</li>
<li>notification 3</li>
</ul>
<div class="title">yesterday <span>-10</span> <i class="fa fa-chevron-down"></i> </div>
<ul>
<li>notification 4</li>
<li>notification 5</li>
</ul>
<div class="title">in last week <span>+32</span> <i class="fa fa-chevron-down"></i> </div>
<ul>
<li>notification 6</li>
<li>notification 7</li>
<li>notification 8</li>
<li>notification 9</li>
<li>notification 10</li>
</ul>
</div>
&#13;
我需要为前N个元素设置背景颜色。例如N = 4
,我想要这个:
如您所见,我为前4个<li>
元素设置了灰色背景色。我怎么能通过jQuery做到这一点?