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" ); } });
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
Post a Comment