ruk·si

🍦 jQuery vs. Vanilla JS

Updated at 2014-10-27 15:15

Always consider if you really need jQuery. Everything used here works in IE9, Chrome, Firefox and on all major mobile browsers. Sadly, sometimes you end up using a JavaScript library that requires jQuery.

Document ready.

document.addEventListener('DOMContentLoaded', function () {
    console.log('Hello');
});

Selectors.

// First found element.
var lochNess = document.querySelector('.monsters');
console.log(lochNess.textContent);

// All found elements.
var monsters = document.querySelectorAll('.monsters');
for (var i = 0; i < monsters.length; i++) {
    console.log(monsters[i].innerHTML);
}

Listening to events.

btn[1].addEventListener('click', function () {
    list.removeEventListener('mouseover', enlarge);
});
btn[1].dispatchEvent('click');