The Web Page Triad
- Declare variables
- Store and retrieve values
- Define and invoke functions
- Define your own classes
- Load and use external modules
- Write event handlers that respond to user and other events
- And much more
- The following selects all bold elements in the document and sets the color of the first one to red.
var elems = document.getElementsByTagName('b'); elems.style.color = 'red';
- Want to change the image in an img tag? The following associates an event handler for the click event of a button.
<img id="myImg" src="prev-image.png"> <button onclick="document.getElementById('myImg').src='new-image.png'">Change Image</button>
- Update the text content of a paragraph (p) element? Set the innerHTML property of the element as shown:
Image Credit: email@example.com/Depositphotos