Last active
August 29, 2015 14:13
-
-
Save joshblack/52d92684f0cabbd444ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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