Skip to content

Instantly share code, notes, and snippets.

@rbk
Last active December 26, 2015 22:29
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 rbk/7223565 to your computer and use it in GitHub Desktop.
Save rbk/7223565 to your computer and use it in GitHub Desktop.
Creating placeholder for ie8 with plain javascript
var forms = document.forms;
for(var i=0; i< forms.length;i++){
for( var t=0; t <forms[i].elements.length; t++ ){
//console.log( forms[i].elements[t].attributes )
var placeholder = forms[i].elements[t].attributes.placeholder.value;
forms[i].elements[t].attributes.value.value = placeholder;
forms[i].elements[t].addEventListener('focus',function(){
this.value = '';
})
forms[i].elements[t].addEventListener('blur',function(){
if( this.value == "" ){
this.value = placeholder;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment