Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Introduction to jQuery What is the DOM?

Anita Amini
Anita Amini
6,389 Points

I don't understand why we need to access DOM when we have our code in our text editor.

I think I understand what the DOM is, well I've listened to the explanation a few times but don't understand why we need to 'access' it.

5 Answers

This article should help you make better sense of it: http://css-tricks.com/dom/

Kevin Korte
Kevin Korte
28,148 Points

mikes02 that is a good article.

My response was going to be that the code in your text editor is not the DOM. The DOM could change from what's in your text editor. Maybe you have a back end langague outputting HTML, that output is going to be in the DOM, but not in your text editor.

Maybe you've used a JS plugin, or ajax. The DOM could change without a page refresh, but your text editor code would still be the same.

Later, down the road, you'll want to access the DOM to do a number of things. Maybe it's dynamic CSS styling, maybe it's client side form validation, maybe it's to show the user an alert, a tooltip, or extra menu options.

The list for DOM manipulation is endless. Learning how to traverse it, and deal with the possibility and extreme likely-hood that the DOM will not reflect what is in your text editor will be very beneficial to you.

Pavle Lucic
Pavle Lucic
10,801 Points

Accessing means selecting html tags on document.

For example if you want to select paragraph in css, you will use selector to access and change p { color:white };

To change color in Jquery, you will "access" DOM and change the color. $("p").css("color", "white");

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

It's sort of like an interface which helps make JavaScript stuff happen. JavaScriot is driven by it. Even simple stuff like getElementById. That;s the way I think of it.

Check out the Mozilla Developer Network documentation for all you need to know about the DOM and how to use it. :)

Anita Amini
Anita Amini
6,389 Points

thank you for the quick and helpful response guys, it's starting to make sense :)