Last active
August 29, 2015 14:15
-
-
Save stephencoe/57a8d286dc7330abd1cb to your computer and use it in GitHub Desktop.
Placeholder polyfill - no jquery
This file contains 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
/** | |
* @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