Skip to content

Instantly share code, notes, and snippets.

@Flobin
Last active May 3, 2017 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flobin/f95c4227ab79dd87333b to your computer and use it in GitHub Desktop.
Save Flobin/f95c4227ab79dd87333b to your computer and use it in GitHub Desktop.
[].slice.call( document.querySelectorAll( '.input' ) ).forEach( function( inputEl ) {
// in case the input is already filled..
if( inputEl.value.trim() !== '' ) {
classie.add( inputEl.parentNode, 'input--filled' );
}
// events:
inputEl.addEventListener( 'focus', onInputFocus );
inputEl.addEventListener( 'blur', onInputBlur );
} );
function onInputFocus( ev ) {
classie.add( ev.target.parentNode, 'input--filled' );
}
function onInputBlur( ev ) {
if( ev.target.value.trim() === '' ) {
classie.remove( ev.target.parentNode, 'input--filled' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment