user752723
user752723

Reputation:

Highlight div that contains date

I'm trying to make code that changes the color of the div (with the class "carrythatweight") if it has the date in it.

This is the HTML I'm using:

<div class="carrythateright">groan...</div>
<div class="carrythateright">what in the world is going on !!!</div>
<div class="carrythateright">stackoverflow is SO helpful. It is now 12/26/2012 !!!!</div>​

This is the script I'm using, but it doesn't really work:

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()

$(document).ready(function() {
    $(".carrythatweight:contains('' + month + '/' + day + '/' + year +'')").css("color", "#00bbbb");
});​

Here is the Fiddle

Upvotes: 0

Views: 136

Answers (1)

John Dvorak
John Dvorak

Reputation: 27287

http://jsfiddle.net/37tR5/2/

I made two fixes in your code to make it work:

1) I replaced some single quotes with double quotes so that the selector gets interpolated as expected: Compare (original)

"...'' + month + '/' + day + '/' + year +'')"

with (fixed)

"...'" + month + "/" + day + "/" + year +"')"

2) I modified the class in the selector to match the class in the divs.

Upvotes: 4

Related Questions