Attaches a class to an HTMLElement.
addClass(className).add() function. The only difference is that this function returns the HTMLElement and thus allows chaining other functions for neater and/or more compact code.Simple example:
let foo = document.getElementById('foo'); foo.addClass('bar');
Chaining methods allows for very compact code:
document.getElementById('foo').addClass('bar').attr('data-value', '123');
… that can also look very neat and readable:
document.getElementById('foo') .addClass('bar') .attr('data-value', '123') ;