while generally I prefer to emulate the HTML5 placeholder attribute, sometimes we want to recreate the behavior but use the original value of the element rather than an attribute. here’s a little plugin that does it (note that the plugin requires an explicit invocation, and is not automatically assigned to all elements (so must be called by dynamically created elements even if run against all inputs, for example, on domready).

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

(function($){

$.fn.restorable=function(){

this.each(function(index,element){

varhandle=$(this);

handle.blur(function(e){

varhandle=$(this);

varvalue=handle.val();

if(value==''){

handle.val(this.defaultValue);

}

});

handle.focus(function(e){

varhandle=$(this);

varvalue=handle.val();

if(value==this.defaultValue){

handle.val('');

}

});

});

};

})(jQuery);

usage..

1

$('input').restorable();

at some point i should test for defaultValue support – if not available, I’d just use val() on the first level of the loop and save it in a variable.

This doesn’t do what it claims to do. If it does, it needs more explanation of how to implement it. It doesn’t even reference the ‘input’ tag anywhere? Not worthy of Google 1st result ranking. Go Google.