How to append class name to body with JavaScript

There will be times when we need to append class to body or other element when that particular page gets loaded.

The other day, I encountered this scenario while refactoring a Rails app.

Here is how I did so using plain JavaScript

window.onload = function() {
    document.body.className += "your-awesome-class";
};