Today I learned...
Important Note
JavaScript does not alter your HTML, but the DOM. It changes what the browser renders.
DOM manipulation methods will not work if the JavaScript file is called before the DOM nodes are parsed and created. To fix this, you can:
- include JavaScript at the bottom of your HTML file
- link the JavaScript file in the head of your HTML document
- use the script tag, set the src attribute to the path to the JS file, and include the defer keyword to load the file after the HTML is parsed
Exercise
- a p with red text that says “Hey I’m red!”
Resources
The Odin Project
https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML#applying_css_and_javascript_to_html
Top comments (0)