Skip to content

Instantly share code, notes, and snippets.

@joshblack
Last active August 29, 2015 14:13
Show Gist options
  • Save joshblack/52d92684f0cabbd444ed to your computer and use it in GitHub Desktop.
Save joshblack/52d92684f0cabbd444ed to your computer and use it in GitHub Desktop.
el.addEventListener('click', function (e) {
e.target.style.display = 'none';
});
// Instead of using jQuery's $('selector') for grabbing an element, just use these
var elem = document.querySelector('selector'); // Returns a DOM Node
var elems = document.querySelectorAll('selector'); // Returns a nodelist
// Then for event listeners it's just:
elem.addEventListener('click', function (e) {
// e is the event,
var event = e,
// e.target will give you what's been clicked
target = e.target;
// You can change styles by accessing the style property
target.style.display = 'none';
// Add a class
target.classList.add('className');
// Remove a class
target.classList.remove('className');
// Remove element
target.parentNode.removeChild(target);
});
// For anything else, just use: http://youmightnotneedjquery.com/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment