javascript - How to add color to an error message using jQuery -
in validation logic in jquery have this:
if (strippedpn.length !== 10) { $('#phonenumber').after('<span color="red" id="errphonenumber">phone number has 10 digits long. </span>'); proceed = false; }
because want error message displays next field, red. doesn't work. what's wrong?
note: tried using css()
before after()
changes color of text inside field (as expected, btw). tried css()
after after()
, doesn't work. tried addclass
.
here's html:
<div> <label for="phonenumber" class="label">phone number</label> <input name="phonenumber" type="text" id="phonenumber" size="13"> </div>
just give style..
<style> #errphonenumber {color:red; } </style>
then apply it...
if (strippedpn.length !== 10) { $('#phonenumber').after('<span id="errphonenumber">phone number has 10 digits long. </span>'); proceed = false; }
or if wanna apply multiple spans/error messages in general....a class better.
<style> .error {color:red;} </style> if (strippedpn.length !== 10) { $('#phonenumber').after('<span class="error" id="errphonenumber">phone number has 10 digits long. </span>'); proceed = false; }
Comments
Post a Comment