tags:

views:

22

answers:

1

I have the following jQuery code that detects if a user has clicked a search button but not typed anything in the text box, if so then they are focused on the textbox and the box turns red. What I want to do is when the user unfocuses (blur) from the textbox regardless of whether they have entered text or not then the box will return to its original color, at the moment it stays red.

code:

$('#submit').click(function()
                {
                    if ( $('#q').val() == '' )
                    {
                        $('#q').focus().css('border-color', '#ff0000'); return false;
                    }
                });
+2  A: 

If I read you correctly:

$('#q').blur(function (){
    $(this).css('border-color', '');
});
Matt Ball
yes this is perfect thanks
Cameron
@Cameron: [the jQuery API docs](http://api.jquery.com/blur) are your friend for this kind of basic stuff.
Matt Ball
I knew it was .blur() but wasn't sure how to check the box using the blur(function() part. Thanks again
Cameron