Jquery add CSS if input empty on .keyup -


im trying add css input on keyup. if input empty add css. i've tried this...

            $(input).keyup(function() {                 var input = $(this).attr('id');                 if( input == "" ) {                   $(input).css( "border", "1px solid #fb9e25" );                 }                }); 

http://jsfiddle.net/dkw7m/

html

<input type="text" id="test" /> 

js:

$("#test").keyup(function() {                 var input = $(this);                  if( input.val() == "" ) {                   input.css( "border", "1px solid #000" );                 }                }); 

i changed black make easier see.

if want multiple id's, try:

<form id="some_form">  <input type="text" />  <input type="text" /> </form> 
$("#some_form input").each(function() {      $(this).keyup(function() {                  var input = $(this);                  if( input.val() == "" ) {                   input.css( "border", "1px solid #000" );                 }                });    }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -