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

CSS jQuery Basics (2014) Creating a Password Confirmation Form Perform: Part 1

Muhammad Rizwan
Muhammad Rizwan
8,595 Points

what is traversing

I am beginner. I really do not understand what does traversing means. How traversing is different from manipulating. If some can explain in simple words please.

3 Answers

Hi Muhammad,

Traversing is all about selection. When you need to traverse, you need to figure out how to get somewhere, or more specifically, how to identify something in a particular area. There's lots of ways to identify, or get to the same spot. You can use IDs, class names, parents, children, etc.

Manipulation is about access and change, and comes after traversing (in thought, but not always in code). Once you figure out how to identify a specific item in your html, then you can manipulate it.

Let's say you had a paragraph inside a div, and you wanted to change the text in that paragraph:

<div id="gothamDiv">
    <p>I'm Batman</p>
</div>

First, you need to traverse to that specific paragraph. There are many ways to do this, but since our div happens to have an ID of "gothamDiv", we'll use that. Don't forget, because we want the paragraph inside we need to include a space and a paragraph selector "p".

$("#gothamDiv p")

Alright, we've traversed, and identified the paragraph we want in our specific Div. Now comes the manipulation, where we access, and in this case alter the text. Again, there's more than one way to do this, but we'll use the method ".text()". Remember, with ".text()", you can retrieve text or set text, depending on whether or not you pass an argument. We want to change the text, so we'll pass an argument that contains our new string.

$("#gothamDiv p").text("I am the night");

Traversing doesn't always come before manipulation, but it helps for the purpose of understanding. For instance, if we wanted to pass an argument containing the text from another paragraph, we would have to traverse 'after' manipulating. Just remember, Traversing gets you where you want to be, and Manipulation does what you want to do.

Hope this helps. :)

Muhammad Rizwan
Muhammad Rizwan
8,595 Points

Wow!! Great Answer. Its clear my mind. Thank you so much

Thank you Chris, that helps a lot! I almost finished watching jQuery basics and was still trying to figure out what traversing means..

Wayne Priestley
Wayne Priestley
19,579 Points

Hi Muhammad,

To traverse something means to cross it.
If something was to traverse your screen it could be crossing left to right.

Hope this helps.

Rifqi Fahmi
Rifqi Fahmi
23,164 Points

damn thats what I am searching for, 'traverse'. Thanks :)

Sandeep Krishnan
Sandeep Krishnan
9,730 Points

thanks everyone for asking and answering. It helping future generations too... Terversing after DOM manipulation is a topic I can't still reckon with.