Reading from elements of the DOM we have selected.
After selecting a piece of the DOM you probably want to do something with it. Before we can do that we have to decide what piece of the DOM element we want to work with.
select an element like this:
let mySelection = document.getElementByID("someID");
then you can interact with it like so:
let someHtml = mySelection.innerHTML;
- selects the html inside the chosen element:
- selects the text inside the chosen element:
mySelection.style.color = 'red'
- This will only read the styles that are directly on the element not styles that are part of a style sheet or inherited.
- change class:
- create Element:
- append child:
- inserts before the selector:
- insert adjacent to the selctor:
insertAdjacentHTML(position, html)-- (position: 'beforebegin', 'afterbegin', 'beforeend', 'afterend')
- clones the selected element/node:
- creates a fragment of the document that can be added in later:
Next Article: NodeLists