Few Newer JavaScript Functions

Here are few newer JavaScript functions: querySelector, querySelectorAll, matchesSelector, and classList.

querySelector is for selecting DOM based on CSS selector. It is native to JS. So, it is faster than earlier methods libraries (jQuery) used to give us. Details here.
Now, libraries will start adopting it as first choice instead of self-made one.

querySelectorAll() is same as above except it will return list. Above will return only one.
querySelectorAll browser readiness.

matchesSelector returns boolean based on selector matches any element or not!

document.addEventListener('click', function(e) {
if ( e.target.matchesSelector('li a') ) {
// proceed
}, false);

matchesSelector browser readiness.


Add class to element as this way:
Similarly, remove and toggle.
Browser readiness.

Supported from IE9 and other from earlier version, this is like .ready() of jQuery. This event is called on Document creation but before all external files (Js, Iframe) are loaded. more here and here.