Created
June 11, 2013 12:54
-
-
Save dziudek/5756567 to your computer and use it in GitHub Desktop.
jQuery placeholder polyfill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function() { | |
jQuery('*[placeholder]').each(function(i, el) { | |
el = jQuery(el); | |
if(el.val() === '') { | |
el.val(el.attr('placeholder')); | |
} | |
el.focus(function() { | |
if(el.val() == el.attr('placeholder')) { | |
el.val(''); | |
} | |
}); | |
el.blur(function() { | |
if(el.val() === '') { | |
el.val(el.attr('placeholder')); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment