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) Making Changes to the DOM DOM Manipulation

travis halarewich
travis halarewich
9,165 Points

I do not know what treehouse coding challenges expect anymore

I have tried multiple different ways to complete the first task in this objective and every single different selector ive tried to use spits out the same answer saying they are all wrong. I even went as far as copying all the code and files into visual studio code and running it locally on chrome and when using the console on chrome the following code works great when i put in the variable 'newParagraph' it gives me my string that i put in the <p> tags, so i am at a loss at what these challenges are looking for now? I tried using querySelector() i tried using document.getElementsByTagName()[0], obviously tried Id selector and nothing wanted to work, if you see something i am missing in my code please let me know

app.js
var contentDiv = document.getElementById('content');
var newParagraph;
newParagraph = document.getElementById('test');
index.html
<!DOCTYPE html>
<html>
    <head>
        <title>DOM Manipulation</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
        <div id="content">
          <p id="test">This is a new paragraph</p>
        </div>
        <script src="app.js"></script>
    </body>
</html>

2 Answers

To create an element you will want to use the createElement() method shown in this video. @2:37 shows creating a list item and assigning it to variable li.

On the video page there is also a link in the teacher's notes to the MDN documentation.

travis halarewich
travis halarewich
9,165 Points

thank you for your fast response and your knowledge on the subject, looking back on it now i can see what you are saying and how it makes sense i just think some of the challenges on here could use some more specific choice words in there delivery. Seeing that i had done exactly what is asked to do but not in the way it was suppose to be done, when getting an answer wrong getting a bit more feed back other than "bummer! you didnt do it correctly" would be nice is all im getting to i guess.

travis halarewich
travis halarewich
9,165 Points

so i got through the first task with what you had mentioned and now the second task is to assign a class to the new paragraph that was just made so i tried using the line of code "newParagraph.className('panel')" and looking at MDN they dont say much about this property and i tried going back into the videos to find where he talked about the "element.className()" property and all i was able to find was him referencing the fact that you need a capital N for Name

There are a couple ways of adding a class to an element in JavaScript.

The following will overwrite any existing classes with "myclass":

element.className = "myclass";

The next two will add the class without overwriting existing classes

element.className += " myclass";  //note the space after the first quote

or

element.classList.add("myclass");