Jquery Plugin – Clear text box on focus.


Quick JQuery plugin i wrote to clear textboxes when mouse is focused on them. And restore previous value on blur.

jQuery.fn.defValue = function(){
    return this.each(function(){
            var defVal = this.defaultValue;
            if($(this).val() == defVal){
                $(this).val('');/* Clear box if it hasnt changed */
            var defVal = this.defaultValue;
            if($(this).val() == ''){

NOTE: This will work on text boxes only not Text area. With some tweeking it can work on text area. I’m just too lazy 🙂 sorry…This is the part where you say challenge accepted!

About the author

Talifhani Luvhengo

A collection of particles named Tali Luvhengo



Page optimized by WP Minify WordPress Plugin