Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Set individual input border color

Tags:

html

jquery

css

Is it possible to set a color of a specific input field using jquery?

I would like to set a border to red if it fails some validations that I wrote and turn it back to black if it is fine.

Any way to do this?

like image 834
shaneburgess Avatar asked Dec 17 '22 20:12

shaneburgess


2 Answers

in your validation code, set the field with the error

$('#afieldID').addClass("error");  

in your validation code, set the field with no error

$('#afieldID').removeClass("error");  

stylesheet code

.error {
    border: solid 2px #FF0000;  
}
like image 124
Aaron Saunders Avatar answered Dec 28 '22 19:12

Aaron Saunders


why do people always want to write there own code what do they think they are programmers ;^ ) you should consider validation plugin

I would do something like

  $('#item_id').addClass('errorClass');

that was you can add put it all in classes and swap as needed

like image 28
mcgrailm Avatar answered Dec 28 '22 20:12

mcgrailm