Codesnipp.it Social Code Sharing

Amber Weinberg

Clear on Focus & Replace if Default (Detached from input)

by Amber Weinberg on Feb 19, 2012

// Found on http://stackoverflow.com/questions/6526943/how-to-make-javascript-find-value-of-input-on-focus-clear-if-its-default-and-k $('input, textarea').each(function() { var $this = $(this), defaultValue = $this.val(); // stores the default value $this.focus( function() { if ($this.val() == defaultValue) { $this.val(""); } }); $this.blur( function() { if ($this.val() == "") { $this.val(defaultValue); } }); });

Can't see the comments? Please login first :)