I'm trying to implement some Javascript that will remove an element and its parent from a page based on whether the date inside the element has gone by.
If for example todays date is December 16, 2014 and the element contains the date December 15, 2014 than I want the element to be removed. I already have some code that I used for a different site of mine that removes the element and it's parent successfully, however the date format for that site is different than the date format on the current site. Applying this code doesn't work for the current site.
Here's the Javascript I have from the other site for removing the element:
<script type='text/javascript'>
jQuery(document).ready(function(){
jQuery('.o-date').each( function(key,value){
console.log(value);
var currentDate = new Date();
var date = new Date(jQuery(value).text());
if(date < currentDate){
jQuery(value).parent().remove();
}
});
});
</script>
Here's the markup on the current site for the element containing the date and it's parent:
<tr data-offer-id="13503" class="special">
<td class="o-date">December 14, 2014 - January 9, 2015</td>
<td class="o-content"></td>
<td class="o-amount">
<select>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</td>
</tr>
EDIT: Here is a jsfiddle for this.
currentDate
meanttoday
?