Fork me on GitHub

jquery-clearinput by afeld

Clears the instructions from an HTML form input on focus, replacing the text if nothing is entered.

Usage

Requires jQuery version Add the class clear-input to any text input element whose value you want cleared when it gains focus. The initial value will be replaced when the input loses focus, and no new text has been entered.

If you prefer to not add classes to your elements, you can alternatively call clearInput() on any jQuery input object.

You can have multiple clear-input fields on a single page, and they will not conflict.

Examples

Using the clear-input class:
      <input name="email" class="clear-input" value="Email address">
    

Using the clearInput() function:
      <input name="email" value="Enter email" id="clear-me">

      <script type="text/javascript">
      $(document).ready(function(){
        $("#clear-me").clearInput();
      });
      </script>
    

Download

You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/afeld/jquery-clearinput

Requirements

Compatible with jQuery v1.2+.

Authors

Aidan Feldman (aidan.feldman@gmail.com)