Day 9: Finishing Intermediate JavaScript on Treehouse Plus: New Contributor

Traversing the DOM
So I learned more about traversing the DOM with JavaScript instead of the sugary jQuery library which makes me feel great. I like jQuery and all, but knowing how to code something in pure JavaScript is something I think every new developer needs to learn and learn before learning any libraries or learning concurrently with JavaScript, like Treehouse does with it’s jQuery and JavaScript courses.
One of my favorite things about this was instead of having to use the
onclick();
event handler to traverse a certain part of the DOM (when something is clicked) you could listen for any type of click events with
addEventListener
to listen for a click on an element specified as the argument to the method. For instance here:
addButton.onclick = addTask; //Set the click handler to the addTask function addButton.addEventListener("click", addTask); addButton.addEventListener("click", ajaxRequest); addButton.onclick = addTask; //Set the click handler to the addTask function addButton.addEventListener("click", addTask); addButton.addEventListener("click", ajaxRequest); This is much faster and easier than traversiing each element with the onclick(); method.