Reputation: 9495
I am trying to get todays date using JS so I add a class to highlight opening hours for the current day.
HTML
<dl class="dl-horizontal hours">
<dt data-day="1">Monday</dt>
<dd data-day="1">17:30 - 11:30</dd>
<dt data-day="2">Tuesday</dt>
<dd data-day="2">17:30 - 11:30</dd>
<dt data-day="3">Wednesday</dt>
<dd data-day="3">17:30 - 11:30</dd>
<dt data-day="4">Thursday</dt>
<dd data-day="4">17:30 - 11:30</dd>
<dt data-day="5">Friday</dt>
<dd data-day="5">17:30 - Midnight</dd>
<dt data-day="6">Saturday</dt>
<dd data-day="6">17:30 - Midnight</dd>
<dt data-day="0">Sunday</dt>
<dd data-day="0">17:30 - 11:30</dd>
</dl>
JS
today=new Date();
thisDay=today.getDay();
$('[data-day='+thisDay+']').addClass('current')();
This does add the .current
to the correct day but I get a JS error
Uncaught TypeError: object is not a function
which breaks all JS after those lines.
Could someone explain what is wrong here and how I can fix this?
Upvotes: 0
Views: 50
Reputation: 9993
Last line should be like this:
$('[data-day='+thisDay+']').addClass('current');
//without () in the end
Upvotes: 2
Reputation: 318232
Change this
$('[data-day='+thisDay+']').addClass('current')();
to
$('[data-day='+thisDay+']').addClass('current');
the last set of parentheses is trying to execute the jQuery object, which is not a function
Upvotes: 2