I have a list of events – I want to only show the ones that are in the past. To do this I was thinking to loop though these elements, find the containing div with the date, and then compare this to todays current date.
A basic structure of these events is as follows:
<div class="past-event">
<span class="event-title">Event 1</span>
<span class="event-date">05.05.19</span>
</div>
<div class="past-event">
<span class="event-title">Event 2</span>
<span class="event-date">20.04.19</span>
</div>
I've used Moment.js to parse the dates. I've used jQuery for this so far (I usually try not to) but this is hosted on a Wordpress site anyway so jQuery is already available. I'm happy to hear any solution and not just a jQuery related one.
Here is a JSFiddle of a simplified version of my code. The way its laid out, the first two elements should be hidden and the second two should be blue (I have added a "blue" class to make it clearer when the code is not working)