jQuery remove text in input on focus

jQuery code:

    var input = $('input.text'); // input text field
    var default_value = input.val();
        if ($.trim($(input).val()) == default_value) input.val('');
        if ($.trim($(input).val()) == '') input.val(default_value);

Or use placeholder feature:

<form class="well">
    <div class="control-group">
        <input type="text" placeholder="placeholder text" />
    <div class="control-group">
        <textarea placeholder="placeholder text (will disappear after typing)" cols="30" rows="5"></textarea>

2 comments on “jQuery remove text in input on focus

Leave a Reply to Lauren Cancel reply

Your email address will not be published. Required fields are marked *