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 Getting a Handle on the DOM Use CSS Queries to Select Page Elements

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

document.title v/s document.querySelector('title')

document.title v/s document.querySelector('title')

when I try to assign a new value, I am able to with document.title, but not with document.querySelector('title').

What can be the reason?

2 Answers

Steven Parker
Steven Parker
231,269 Points

These are different kinds of things. While document.title is a string, document.querySelector("title") is an element.

The equivalent string to document.title would be document.querySelector("title").textContent.

Steven Parker
Steven Parker
231,269 Points

Frequent use helps make it stick in your mind, but even so you can't expect to remember everything. Whenever I forget, I just look up the specs on MDN, like for document.title and for document.querySelector.