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

Fabian Pijpers
PRO
Fabian Pijpers
Pro Student 32,488 Points

When using the exact same syntax you use in the video's i get a null returned! Do you know why?

document.querySelector('[title=label]') it returned the: null

The above is what i entered into the developer console.

Adam Beer
Adam Beer
11,272 Points

Please show your code.

3 Answers

Martin Lecke
Martin Lecke
14,355 Points

Hi

You have missed one step in the video if you are tagging along the code-along.

On the 02:03 minute mark he adds the title="label" on the html tag. You dont have it in your html else you might have misspelled it. Check the video at 02.03

nathan goel
nathan goel
7,281 Points

Same kind of issue for me. 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!!

Adam Beer
Adam Beer
11,272 Points

Try this Nathan,

document.getElementsByClassName("textDesign")

or

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

If it doesn't work please show your whole html/javascript code.