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) Getting a Handle on the DOM Selecting by Id

Vic Mercier
Vic Mercier
3,276 Points

"p.description"

If I understand well, that means the p (in the app.js) represents the p tag in the html file? I mean:("p.description");

js/app.js
const name = document.querySelector("p.description");

name.style.color = "purple";
index.html
<!DOCTYPE html>
<html>
  <head>
    <title>JavaScript and the DOM</title>
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
    <h1 id="myHeading">JavaScript and the DOM</h1>
    <p>Making a web page interactive</p>    
    <p class = "description">Things that are purple:</p>

    <ul>
      <li>grapes</li>
      <li>amethyst</li>
      <li>lavender</li>
      <li>plums</li>
    </ul>
    <script src="app.js"></script>
  </body>
</html>

2 Answers

Steven Parker
Steven Parker
231,008 Points

That sounds right.

The selector "p.description" would target "paragraph element(s) that have the class description".

But I'm not sure how that relates to your challenge, because the "View Challenge" button in the upper right is linked to a completely unrelated challenge! This might be something you would want to report to Support.

Jawann Carmona
Jawann Carmona
19,556 Points

You just want to use ("description") rather than ("p.description"). 'p' isn't actually part of the class name.

const name = document.querySelector("description");

You might also have to use document.getElementByClassName('description');

Steven Parker
Steven Parker
231,008 Points

I think you mean getElementsByClassName (plural).

Jawann Carmona
Jawann Carmona
19,556 Points

oops. yes, getElementsByClassName.