jQuery to pure Javascript examples – 2

With this post we continue the series of examples to replace jQuery with pure javascript.

Add class

// jQuery

// Pure Javascript

Remove class from an element

// jQuery

// Pure Javascript

Remove class from multiple elements

// jQuery

// Pure Javascript
var elems = document.querySelectorAll(".my-elms.my-class");

[].forEach.call(elems, function(el) {

// or in a line using the ES6 standard
Array.from(document.querySelectorAll('.my-elms.my-class')).forEach((el) => el.classList.remove('my-class'));

Check if an Element Contains a Class

// jQuery

// Pure javascript

Leave a Comment

Your email address will not be published. Required fields are marked *