Stop saying “Vanilla JavaScript”

Vanilla DOM is much better

Often I see comments on StackOverflow, comments in blogs, and criticism of JavaScript mentioning “vanilla JS.”

Vanilla JavaScript is not the DOM. The DOM is what people are talking about when they say that JavaScript is terrible. Raw DOM methods are what people mean when they ask for solutions without jQuery.

The DOM is terrible

JavaScript developers know all too well how terrible the DOM is. First of all, there’s the terribly wordy methods:

// DOM
document.getElementById(“my-thingy”).style.background = “blue”;
// jQuery
$("#my-thingy").css("background", "blue");
// DOM
var elem = document.getElementById("toggle-class");
if(elem.className.indexOf("orig-class") === -1){
elem.className += "orig-class";
} else {
elem.className.replace("orig-class", "");
}
// jQuery
$("#toggle-class").toggleClass("orig-class");

Then, the unnecessary gotchas:

// DOM
// Better put that 'false' at the end, or else!
document.getElementById("thingy1").addEventListener("click", fnOnClick, false);
// jQuery
$("#thingy1").on("click", fnOnClick);

And the numerous other bad decisions, like live NodeLists (but only for some things) and other stuff only the Java lovebirds at W3C could think of.

No wonder everyone still uses jQuery

The DOM is what contains all of this badness. The worst thing JavaScript has is some slight issues with this. So, stop saying “Vanilla JS” when you really mean “the DOM.” It’s much more correct, specific, and helpful to newcomers.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.