Simple jQuery on input fields to remove text upon user focus

robertbanh

robertbanh

3 years ago · 1,032 views
$("#email").focus(function() {
    if ($(this).val() == $(this).attr('rel'))
        $(this).val('');
});
$("#email").blur(function() {
    if ($(this).val() == '')
        $(this).val($(this).attr("rel"));
});
Raw

<input type='text' id='email' value='Enter your Email' rel='Enter your Email' />

The content will contain "Enter your Email". But when the user enters the field, it will clear out the value... and vise versa.

Tagged: blur focus javascript jquery
Comments are only visible to Forrst members. Log in or Request an invite.
3 new notifications