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 trialA X
12,842 PointsI'm not clear how (jQuery?) manipulates the DOM or why.
I watched Andrew's video on jQuery documentation, and I'm still not clear what the DOM is other than a way of charting the components of a website. What confused me significantly is that Andrew's video didn't explain what is manipulating the DOM, and why that's useful. He didn't relate jQuery to this manipulation of the DOM directly, and I'm not clear if the manipulation of the website with (jQuery?) is temporary or permanent and why either would be useful. Can someone help clear this up for me? Thanks!
2 Answers
Adam Duffield
30,494 PointsManipulating the DOM or Document Object Model is generally just a fancy way to say "change the static html". Once your html is loaded it is static and it doesn't change unless you manipulate the DOM with Jquery.
e.g. An online grocery checklist will start with just the html for "Add item". When clicking this button you are manipulating the DOM by adding html <li> tags onto the grocery checklist. This changes the Document Object of the entire page to be the same but with an extra list tag. Think of the DOM as a tree of Html elements which should stay the same. However Jquery allows you to change it how you see fit.
Hope this helps,
Adam
Antonio De Rose
20,885 PointsHi, just as Adam, had mentioned, it is the way of changing the static html (index.html), answering to your question, manipulating the DOM, is changing the static html, by using jQuery only temporarily, that would not write the changes permanently, for instance see example $('button').click(function{ $('a').attr('href', 'http://github.com') }); the above example, sets the 'href' attribute of the 'a' element, equal to http://github.com, as a result of the button click event. Depending on the user interaction, we are able to add, dynamic functionality to the static page.
$('a').attr('href', 'http://github.com') //this very line is DOM manipulation, this is done without the page load.