I wanna select some sibling elements. So I used jQuery .next() but I don't know how to repeat.
// Repeat 3 times
$('#after').next().addClass('selected');
$('#after').next().next().addClass('selected');
$('#after').next().next().next().addClass('selected');
.selected {
color: red;
}
<ul>
<li>1</li>
<li>2</li>
<li id="after" data-num="3">3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
How can I make a repeated jQuery next() as specified value by for loop, like this? (of course this is not working.)
$('#after')
for(var i=0; i<$('#after').data('num'); i+=1){
.next().addClass('selected')
}
;