Stylize Placeholder

Asked

Viewed 42 times

-4

if ($("#nome").val() === ""){
    $("#nome::placeholder").css("color", "red");
    $("#nome").focus();
    return false;
}

My goal is set the color of placeholder for red if the name field is emptiness

I followed that example

http://jsfiddle.net/erackson/9kaHw/2/

But it didn’t work.

Where am I going wrong?

Note: The phocus works but the placeholder doesn’t stay red

  • Dude, but if the field isn’t empty like you want the placeholder to appear, if you type a . which is in the input the placeholde already goes away...

  • in the case is when you submit the form that the check is done. In the form of the reply I posted, solves the problem!

1 answer

-1

if ($("#nome").val() === ""){
    $("#nome").addClass("red").focus();
    return false;
}

I created a class

Browser other questions tagged

You are not signed in. Login or sign up in order to post.