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 trialkaran Badhwar
Web Development Techdegree Graduate 18,135 Pointsdocument.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
231,275 PointsThese 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
.
karan Badhwar
Web Development Techdegree Graduate 18,135 PointsOkay Thankyou so much
karan Badhwar
Web Development Techdegree Graduate 18,135 Pointskaran Badhwar
Web Development Techdegree Graduate 18,135 PointsHi Steven, i understood it, but how do we know when returns a string or an element?
Steven Parker
231,275 PointsSteven Parker
231,275 PointsFrequent 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.