Reputation: 63
Simple question; I want to highlight some text if it is monday, some other when it's tuesday etc.
$('p.day:eq("' + new Date().getDay() + '")').addClass('today');
I feel like I'm so close.
Upvotes: 2
Views: 968
Reputation: 16961
$('p.day:eq(' + new Date().getDay() + ')').addClass('today');
You need to take out the quotes in the :eq()
- pass the value as an integer, not a string.
Also, using .getDay()
, Sunday is day number 0, so you'll either need to change the order of your days, or create another work-around for this.
Upvotes: 3
Reputation: 15338
you should do :
$('p.day').eq(new Date().getDay()-1).addClass('today');
Upvotes: 4
Reputation: 150253
$('p.day').eq(new Date().getDay()).addClass('today');
Or using the :eq
psudo css selector:
$('p.day:eq(' + new Date().getDay() + ')').addClass('today');
The number should be a number and not a string.
Upvotes: 2