Smashed Blog Development

Tag Archive: focus

:focus support with jQuery

Comments Off

This is an oldie, but a goodie. I don’t find myself using this as much these days, but for when you need some old browser support for the CSS :focus property.

$('input[type="text"]').focus(function() {
    $(this).addClass("focusField");
    if (this.value == this.defaultValue){
        this.value = '';
    }
    if(this.value != this.defaultValue){
        this.select();
    }
});
$('input[type="text"]').blur(function() {
    $(this).removeClass("focusField");
});