Skip to content

Instantly share code, notes, and snippets.

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