Skip to content

Instantly share code, notes, and snippets.

@stephencoe
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephencoe/57a8d286dc7330abd1cb to your computer and use it in GitHub Desktop.
Save stephencoe/57a8d286dc7330abd1cb to your computer and use it in GitHub Desktop.
Placeholder polyfill - no jquery
/**
* @license http://opensource.org/licenses/MIT
* Polyfill [].forEach.call using the polyfill service
* @link https://github.com/Financial-Times/polyfill-service
*/
if(false === ('placeholder' in document.createElement('input'))){
var inputs = document.getElementsByTagName('input');
[].forEach.call(inputs, function(input){
if(input.getAttribute('placeholder')){
input.value = input.getAttribute('placeholder');
input.onclick = function(){
if(this.value === this.getAttribute('placeholder')){
this.value = '';
}
}
input.onblur = function(){
if(this.value === ''){
this.value = this.getAttribute('placeholder');
}
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment