Welcome! Today's mission is to supercharge our webpages with JavaScript! We'll master the art of creating new HTML elements, setting their attributes, and dynamically swapping the content. Are you ready? Let's dive in!
The DOM (Document Object Model) structures a webpage much like a family tree. JavaScript
manipulates the DOM
to transform your webpage.
Our webpage currently holds a welcome message. Let's jazz it up with JavaScript!
JavaScript
is used to create new HTML elements with the document.createElement()
function. Here's how we do it:
This document.createElement("p")
spells into existence a new paragraph element, currently an empty shell <p></p>
. It's almost like having an actor for our play (the webpage) but without lines to say. To affix content, embeds text within our ledged element, breathing life into it as .
