I have a static event listing in HTML where I would like to add a CSS class to past and current events dynamically using javascript.
Each event listed will need to display either a single date or a date range, therefore parsing the date (I'm thinking) will need to be done using a data-* attribute—something which I've never worked with before in this sense.
HTML Markup:
<div class="events-list-wrapper">
<div class="event">
<p class="date" data-date="21-01-2017"><span>Jan</span> 17-21</p>
<h3>Event Title</h3> ...
</div>
<div class="event">
<p class="date" data-date="29-08-2017"><span>Aug</span> 29</p>
<h3>Event Title</h3> ...
</div>
<div class="event">
<p class="date" data-date="12-09-2017"><span>Sept</span> 10-12</p>
<h3>Event Title</h3> ...
</div>
</div>
Here's the fiddle I've been working with, https://jsfiddle.net/t2v21oh6/1/ edit: https://jsfiddle.net/t2v21oh6/4/. I'm not that strong with javascript, and my code isn't working. Not sure why.