← CodePrimer
JavaScript
Beginner
Dom
createElement and appendChild
How do I add a new element with JS?
Create + append pattern.
const p = document.createElement('p');
p.textContent = 'This is a new paragraph!';
document.body.appendChild(p);
Notes
Build nodes, set text, then attach to the tree.
Keywords: createElement · appendChild · dom
Related
JavaScript
document.getElementById
How do I select one element by id?
JavaScript
document.querySelector
How do I select with a CSS selector?
JavaScript
document.querySelectorAll
How do I select every matching element?
JavaScript
addEventListener click
How do I make a button show an alert?
JavaScript
Arrow function event listener
Can I use an arrow function for events?
JavaScript
Live input event
How do I react as the user types?