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 JavaScript and the DOM (Retiring) Traversing the DOM Getting the First and Last Child

Sean Fallon
Sean Fallon
8,516 Points

I notice .nextElementSibling is read only and you can't color text.

I don't understand why this is read only. What if I want to color or style the text of the next element? How would I select that element?

3 Answers

If you go to MDN to read Element.children, you will see that is also read only. But the teacher use it to manipulate the children property all the time.

element.children

Read only means that you CANNOT assign directly

You still can do OOP like code below.

textNode.nextElementSibling.style.color = 'red'

dude, please try it yourself. It CANNOT be re-assign, but you can manipulate its property.

Sean Fallon
Sean Fallon
8,516 Points

I think there is a misunderstanding. That did not answer my question. My question was what if I want to color the next sibling. Clearly I can't use .nextElementSibling because its read only. How would I go about doing that?

Sean Fallon
Sean Fallon
8,516 Points

I read the MDN and I've created several jsfiddles testing it. I got it to work now. Still a little confused on how and when something is not manipulatable.

https://jsfiddle.net/SeanMF/46uvrgew/7/

I think you will get improved after practice and experience. read MDN and test out. I'm also on this way of endless learning.