Reputation: 2021
How to get the next day after .selected?
$('day.selected').next('day')
works only for days inside the same week.
<calendar>
<month>
<week>
<day/>
<day class='selected'/>
</week>
<week>
<day/> //How to get this?
<day/>
</week>
</month>
<month>
.
.
</calendar>
Upvotes: 1
Views: 65
Reputation: 61063
To handle all possible scenarios, something like this could be done:
var curDay = $('.selected');
var nextDay;
if ( curDay.next('day') ) {
nextDay = curDay.next('day');
} else if ( curDay.closest('week').find('day') ) {
nextDay = curDay.closest('week').find('day:first-child');
} else if ( curDay.closest('month').siblings('month').find('week day') ) {
nextDay = curDay.closest('month').next('month')
.find('week:first-child day:first-child')
}
Arun's answer is better, though.
Upvotes: 1
Reputation: 388316
As a general solution to find the next day element(irrespective of the parent element)
var idx = $('day.selected').index('day'),
$next = $('day').eq(idx + 1);
Upvotes: 6