Working with JS-generated DOM elements.
Get access to the root div
Append a div to it
Put text into it
- To create a user interface with JavaScript you will need a place to append your JavaScript DOM (Document Object Model) elements. This will be the
root
of our application. - Get access to that element using the document's API.
- We create our element and add properties to it.
- Finally, appended it to the DOM element.
<body>
<div id="root"></div>
<script type="text/javascript">
const rootElement = document.getElementById('root');
const element = document.createElement('div');
element.textContent = 'Hello World';
element.className = 'container';
rootElement.appendChild(element);
</script>
</body>