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 trialAlexisca hall
23,683 PointsHow would you create a new h1 element with JavaScript? document. (" "); Submit Answer
How would you create a new h1 element with JavaScript?
document. (" "); Submit Answer
3 Answers
George Raymond
3,087 Pointsdocument.createElement("h1");
Prsicilla Anesu Muzerengwa
12,577 Points<!DOCTYPE html>
<html>
<body>
<p>Click the button to create a h1 element with some text.</p>
<button onclick="myFunction()">Click to create</button>
<script>
function myFunction() {
var myStyle = document.createElement("H1");
var myText = document.createTextNode(prompt("This is an example of text written in H1");
h.appendChild(myText);
document.body.appendChild(myStyle);
}
</script>
</body>
</html>
Prsicilla Anesu Muzerengwa
12,577 PointsThis code shows an example of how to use document.createElement