How to clear input field on focus

Handy jQuery plugin for clearing an input field on focus. Found this a while ago on bassistance blog.

Plugin for clearing input field on focus

$.fn.clearOnFocus = function() {
            return this.focus(function() {
        if( this.value == this.defaultValue ) {
            this.value = "";
        }
        }).blur(function() {
            if( !this.value.length ) {
                this.value = this.defaultValue;
            }
        });
    };

You can clear the input field by using:

$(document).ready(function(){
        $('span.sb-question-cbox').click(function(){
            $(this).toggleClass('sb-question-cbox-selected');
        });
        $('input.email').clearOnFocus();
    });
Posted
Views | Favorited 0 Times

Comments (0)

Leave a comment...