← Back to HTML DOM
Question 15
Create and Append New Element
Create and Append New Element
Create a new paragraph element with the text "This paragraph was created with JavaScript!" and append it to the div with id="container". Platform-Provided HTML (READ-ONLY):<div id="container"><p>Existing paragraph.</p></div>Steps: 1. Usedocument.createElement()to create a new<p>element 2. Set its textContent to "This paragraph was created with JavaScript!" 3. Usedocument.getElementById()to select the container 4. UseappendChild()to add the new paragraph to the container
Expected Output:
<div id="container"> <p>Existing paragraph.</p> <p>This paragraph was created with JavaScript!</p> </div>
= newline. No newline after the last line.
Hints4 available
Sign in to use hintsTopics:
HTML DOM
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (clog, fn, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.