Assign element to variable
Create a paragraph element and assign it to the newParagraph variable.
Ive tried everything mentioned in the last two sections but Im not sure what I am doing wrong. Please help
var contentDiv = document.getElementById('content'); var newParagraph = document.getElementById('p');
<!DOCTYPE html> <html> <head> <title>DOM Manipulation</title> </head> <link rel="stylesheet" href="style.css" /> <body> <div id="content"> <p>This is a paragraph</p> </div> <script src="app.js"></script> </body> </html>
anthony amaro8,222 Points
the question says Create a paragraph element and assign it to the newParagraph variable. you are trying to get an element with an id of p. the way to create an element
const pa = document.createElement('p');
hope this helps
Gareth Partridge13,408 Points
The Following worked for me:
var newParagraph = document.createElement("p");
But what I dont understand is where is the p coming from ? there is no reference to the p anywhere. why is it not.
var newParagraph = document.createElement("newParagraph");