It keeps the presentation (CSS/styling) nicely separate from the
JavaScript and makes both much easier to deal with.
So the JavaScript would be something like (note I changed round the
selector to ":text.date", more efficient this way):
$(document).ready(function(){
$(":text.date").each(function (i) {
if(parse(this.value) < Date.getTime()) {
$(this).addClass("pastDate");
}
});
})
And in the CSS:
.pastDate {
color: red;
}
Karl Rudd
On Mon, Dec 29, 2008 at 11:52 AM, Matt <matt.neilson@gmail.com> wrote:
>
> Hi,
>
> I'm trying to make text red when a date in an input field occurs in
> the past. However, it isn't working when I try it out.. I'm new to
> JQuery, so i'm not sure what i'm doing wrong..
>
> $(document).ready(function(){
> $(".date:text").each(function (i) {
> if(parse(this.value) < Date.getTime()) {
> this.style.color = "red";
> }
> });
> });
>
> This is one of the input fields that I want it to turn red.
>
> <input class="date" type="text" value="11/17/2008" name="expires_256"/
>>
>
> Any ideas? I'd love the help. :)
>
> Thanks in advance,
>
> Matt
No comments:
Post a Comment