user752723
user752723

Reputation:

not :contains isn't working

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>

Fiddle

Upvotes: 0

Views: 330

Answers (3)

Matthew Cox
Matthew Cox

Reputation: 13672

Your quotes are incorrect.

$(".whocares:not(:contains('" + month + '/' + day + '/'+ year + "'))").remove();​

Upvotes: 1

faino
faino

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

axel.michel
axel.michel

Reputation: 5764

Your quotes are wrong. It should be something like this:

$(".whocares:not(:contains('" + month + "/" + day + "/"+ year+"'))").remove();​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Upvotes: 7

Related Questions