Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 1.39 KB

01-react-create-a-user-interface-with-vanilla-javascript-and-dom.md

File metadata and controls

41 lines (28 loc) · 1.39 KB

02. Create a User Interface with Vanilla JavaScript and DOM

MHF Notes

Working with JS-generated DOM elements.

Get access to the root div

Append a div to it

Put text into it

Egghead Notes

  • 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>

Additional resource