Jump to Categories

Vanilla JS

Contains class name

document.getElementById('someID').classList.contains('thatClass')

Add event listener to class items


const navdemos = Array.from(document.querySelectorAll('nav.demos > .demo'));

navdemos.forEach(link => link.addEventListener('click', (ev) => {
	ev.preventDefault();
	navigate(ev.target);
}));

Loop through classes


var dropdowns = document.getElementsByClassName('dropdown');
for (var i = 0; i < dropdowns.length; i++) {
dropdowns[i].classList.remove('show');
}

Keypress

document.getElementById('menu-btn').addEventListener('keydown', function(e) {
	if(e.keyCode == 9) {
		e.preventDefault();
	}
});

Refs