Posted By

rhysburnie on 11/11/11


Tagged

jquery placeholder


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

spee66


Polyfill placeholder functionality for inputs


 / Published in: jQuery
 

Assumed support detection: Modernizr otherwise use some other

  1. /**
  2. * Augment placeholder functionality for inputs
  3. */
  4. if(!Modernizr.input.placeholder){
  5. $('input[placeholder]').each(function(){
  6. var el = $(this)
  7. , placeholder = el.attr('placeholder')
  8. ;
  9.  
  10. el.bind({
  11. focus: function()
  12. {
  13. var el = $(this);
  14. if($.trim(el.val())==placeholder) el.val('');
  15. }
  16. , blur: function()
  17. {
  18. var el = $(this);
  19. if($.trim(el.val())=='') el.val(placeholder);
  20. }
  21. });
  22.  
  23. if($.trim(el.val())=='') el.val(placeholder);
  24. });
  25. }

Report this snippet  

You need to login to post a comment.