JavaScript JavaScript and the DOM Getting a Handle on the DOM Using CSS Queries to Select Page Elements

nathan goel
nathan goel
6,362 Points

I try to use document.querySelector with a title attribute, it returns null in console. I don't see what I missed there.

Here is my code in the html page: <p title="firstParagraph" class="textDesign"> Lorem ipsum dolor sit amet, consectetur adip... </p>

That is the result in the console:

document.querySelector('[title=firstParagraph]') null

Help, please!!

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 78,545 Points

It looks like your CSS query in your method isn't quite right.

In the absence of a link I can only make a best guess as to the exact selector you need but try passing the following in your querySelector method.

document.querySelector('[title="firstParagraph"]')