Reputation:
What did I do wrong? When I run this code, nothing is displayed.
The JavaScript code:
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
$(".whocares:not(:contains('' + month + '/' + day + '/'+ year + ''))").remove();
And the HTML:
<div class="whocares">hi</div> <div class="whocares">12/26/2012 i like cake two</div> <div class="whocares">hi</div>
Upvotes: 0
Views: 330
Reputation: 13672
Your quotes are incorrect.
$(".whocares:not(:contains('" + month + '/' + day + '/'+ year + "'))").remove();
Upvotes: 1
Reputation: 3224
Always make sure you are escaping out of the string properly when trying to include variables. This works just fine if you use double quotes instead:
$(".whocares:not(:contains('" + month + "/" + day + "/" + year + "'))").remove();
Upvotes: 1
Reputation: 5764
Your quotes are wrong. It should be something like this:
$(".whocares:not(:contains('" + month + "/" + day + "/"+ year+"'))").remove();
Upvotes: 7