Lego2012
12/13/2016 - 3:29 PM

Clear form field on focus and restore if empty

Clear form field on focus and restore if empty

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

<!-- Clear Input on Focus, Refill on Blur -->

    // clear form field on focus and restore if empty
    // http://www.harjeet.in/on-focus-clearset-input-fields-with-jquery/
    $( '.site-tagline input[type="text"], .newsletter input[type="text"]' ).each(function() {
        var default_value = this.value;
        $( this ).focus(function(){
            if( this.value == default_value ) { this.value = ''; }
        });
        $( this ).blur( function(){
            if( this.value == '' ) { this.value = default_value; }
        });
    });