Posted By

gdesjardins on 05/04/12


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

hurcy
pibot77
Priestd09


make HTML5 placeholders work in non supportive browsers


 / Published in: JavaScript
 

make HTML5 placeholders work in non supportive browsers

  1. // make HTML5 placeholders work in non supportive browsers
  2. $("input[placeholder]").each(function(){
  3. if($(this).val()==""){
  4. // $(this).addClass('hasplaceholder');
  5. $(this).val($(this).attr("placeholder"));
  6. $(this).focus(function(){
  7. if($(this).val()==$(this).attr("placeholder")) $(this).val("");
  8. // $(this).removeClass('hasplaceholder');
  9. });
  10. $(this).blur(function(){
  11. if($(this).val()==""){
  12. // $(this).addClass('hasplaceholder');
  13. $(this).val($(this).attr("placeholder"));
  14. }
  15. });
  16. }
  17. });
  18.  
  19. $('form').submit(function(evt){
  20. $('input[placeholder]').each(function(){
  21. if($(this).attr("placeholder") == $(this).val()) {$(this).val('');}
  22. });
  23. });
  24. });

Report this snippet  

You need to login to post a comment.