Skip to content

Instantly share code, notes, and snippets.

@jtulk
Created August 10, 2015 17:45
Show Gist options
  • Save jtulk/7caa079ff366007489a3 to your computer and use it in GitHub Desktop.
Save jtulk/7caa079ff366007489a3 to your computer and use it in GitHub Desktop.
Example #2: Rewriting jQuery's .each() in Vanilla JS
// Select all HTML elements with class .text-input
var inputs = document.getElementsByClassName('text-input');
// Create event handling functions
function textInputFocusHandler(){ console.log('focus');}
function textInputBlurHandler(){ console.log('blur'); }
// Attach focus & blur handlers to selected inputs
inputs.addEventListener('focus', textInputFocusHandler);
inputs.addEventListener('blur', textInputBlurHandler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment