<tr>
<td><div class="click">a</div></td>
</tr>
<tr>
<td><div class="click">b</div></td>
</tr>
<tr>
<td><div class="click">c</div></td>
</tr>
<tr>
<td><div class="click">d</div></td>
</tr>
<tr>
<td><div class="click">e</div></td>
</tr>
<tr>
<td><div class="click">f</div></td>
</tr>
<tr>
<td><div class="click">g</div></td>
</tr>
<tr>
<td><div class="click">h</div></td>
</tr>
<tr>
<td><div class="click">i</div></td>
</tr>
<tr>
<td><div class="click">j</div></td>
</tr>
<tr>
<td><div class="click">k</div></td>
</tr>
<tr>
<td><div class="click">l</div></td>
</tr><tr>
<td><div class="click">m</div></td>
</tr>
<tr>
<td><div class="click">n</div></td>
</tr>
<tr>
<td><div class="click">o</div></td>
</tr>
</table>
$('.click').click(function(){
$(this).addClass('red');
})
LIVE: http://jsbin.com/ibofis/1/edit
this working ok, but i would like add for this addClass for 3 next elements.
For example if i click on c then class .red should add for: c, d, e and f.
How can i make it?
3 bus timetable overview: Normally starts operating at 05:15 and ends at 23:22. Normal operating days: everyday.
3 (National Express Coventry) The first stop of the 3 bus route is Arena Shopping Park and the last stop is Warwickshire Shopping Park. 3 (Binley) is operational during everyday. Additional information: 3 has 55 stops and the total trip duration for this route is approximately 58 minutes.
AC7 (ADVANCE COACH) (Cross Border Service) The first stop of the AC7 (ADVANCE COACH) bus route is Yishun Temp Bus Int and the last stop is Ciq Johor Bahru. AC7 (ADVANCE COACH) (Ac7 Yishun Temp Int - Jb Ciq) is operational during everyday.
Singapore Bus Services was renamed SBS Transit Ltd on 1 November 2001. The new name reflects our multi-modal status as we move from being just a bus operator to the provision of both bus and train services. We have retained "SBS" in the new company name to remember our roots and preserve our long heritage.
Try this:
$('.click').click(function(){
var $this = $(this).closest('tr');
$this.nextUntil().filter(':lt(3)').add($this).find('div').addClass('red');
});
http://jsbin.com/ibofis/2/edit
Add this to the bottom, after the $(this).addClass('red');
line:
$(this).closest('tr').nextAll(':lt(3)').find('div').addClass('red');
$('.click').click(function(){
$(this).addClass('red');
var counter = 0, clickedEl = this;
$('.click').each(function(ind, el){
if(counter-- > 0){
$(el).addClass('red');
}
if(el == clickedEl){
counter = 3;
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With