Advertisement
Neolot

jQuery - Autoclear input or textarea

Feb 2nd, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($) {
  2.     $(function() {        
  3.         $('#selector').each(function(){
  4.             var text = $(this).val();
  5.             $(this)
  6.                 .focusin(function(){
  7.                     $(this).addClass('focus');
  8.                     if ($(this).val() == text) $(this).val('');
  9.                 })
  10.                 .focusout(function(){
  11.                     if ($(this).val() == '') $(this).val(text);
  12.                     $(this).removeClass('focus');
  13.                 });
  14.         });
  15.     })
  16. })(jQuery)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement