Posted By

Meander365 on 09/11/10


Tagged

javascript input jquery title watermark


Versions (?)

Using Input Title As Initial Text - Hide When On Focus


 / Published in: jQuery
 

  1. function watermark ($obj) {
  2.  
  3. var prev;
  4.  
  5. $obj.each(function() {
  6. if ($(this).attr("title")) $(this).val($(this).attr("title")).addClass("greyout");
  7. });
  8.  
  9. $obj
  10. .focus(function()
  11. {
  12. if ($(this).val()==$(this).attr("title")) {
  13. prev = $(this).val();
  14. $(this).val("").removeClass("greyout");
  15. }
  16. })
  17.  
  18. .blur(function()
  19. {
  20. if($(this).val()=="") {
  21. $(this).val(prev).addClass("greyout");;
  22. }
  23. });
  24.  
  25. }

Report this snippet  

You need to login to post a comment.