DOM Series #3
The HTML DOM Document Object
The document object represents your web page.
If you want to access any element in an HTML page, you always start with accessing the document object.
#100DaysOfCode #javascript #CodeNewbie #programmer #html #Website #freeCodeCamp
Finding HTML Elements
MethodDescription
document.getElementById(id): Find element by element id
document.getElementsByTagName(name): Find elements by tag name
document.getElementsByClassName(name): Find elements by class name
Changing HTML Elements
element.innerHTML = new html content
element.attribute = new value
element.style.property = new style
element.setAttribute(attribute, value) = Change the attribute value of an HTML element
Adding & Deleting Elements
document.createElement: Create an HTML element
document.removeChild: Remove an HTML element
document.appendChild: Add an HTML element
document.replaceChild(new, old): Replace an HTML element
document.write(text): Write into the HTML output stream
Adding Events Handlers
document.getElementById(id).onclick = function(){code}
Adding event handler code to an onclick event
Here Is DOM #2
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.
