JavaScript JavaScript and the DOM Making Changes to the DOM DOM Manipulation

Unable to assign paragraph element to the given variable

As shown in the code, I have to create a paragraph element and assign it to variable newParagraph. I tried using document.getElementById , getElementsByTagName('p')[0] and getElementsByClassName (I gave the tag some id and class). I was able to manipulate the element using .style and everything. However, I am unable to complete the task. When I click on 'Check Work', I get an error saying "Make sure that you assign a '<p>' element to 'newParagraph'." Please help me solve this problem.

var contentDiv = document.getElementById('content');
var newParagraph = document.querySelector('p');
<!DOCTYPE html>
        <title>DOM Manipulation</title>
    <link rel="stylesheet" href="style.css" />
        <div id="content">
        <script src="app.js"></script>

1 Answer

Daniel Turato
.a{fill-rule:evenodd;}techdegree seal-36
Daniel Turato
Java Web Development Techdegree Graduate 30,118 Points

I believe that you're not meant to create the paragraph in raw html but instead create it through javascript. You can achieve this by using this method. You can read more about this in the docs here -


Thank you. I had just finished watching the video and still forgot to use createElement() silly of me, haha