Posted By

mihael on 12/14/11


Tagged

jquery placeholder html5


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Balamir
BrockSamsom


jQuery [input] Placeholder


 / Published in: jQuery
 

jQuery for inputy attribute "placeholder".

  1. ##### HTML #####
  2.  
  3. <input type="text" value="" placeholder="Write some instructions here" />
  4.  
  5. ##### jQuery #####
  6.  
  7. // INPUT PLACEHOLDER
  8. //---------------------------
  9. $("'[placeholder]'").focus(function() {
  10. var input = $(this);
  11. if (input.val() == input.attr("'placeholder'")) {
  12. input.val("''");
  13. input.removeClass("'placeholder'");
  14. }
  15. }).blur(function() {
  16. var input = $(this);
  17. if (input.val() == "''" || input.val() == input.attr("'placeholder'")) {
  18. input.addClass("'placeholder'");
  19. input.val(input.attr("'placeholder'"));
  20. }
  21. }).blur();
  22.  
  23. $("'[placeholder]'").parents("form").submit(function() {
  24. $(this).find("'[placeholder]'").each(function() {
  25. var input = $(this);
  26. if (input.val() == input.attr("'placeholder'")) {
  27. input.val("''");
  28. }
  29. })
  30. });
  31. //---------------------------

Report this snippet  

You need to login to post a comment.