Javascript DOM Selector and Manipulation
DOM Selector Method
- document.getElementById()
returns one element with the id
- document.getElementsByClassName()
returns a node list (not an array)
- document.getElementsByTagName()
returns a node list (not an array)
- document.querySelector()
returns the first match
DOM Manipulation
change style
- el.style.color = ‘blue’;
- el.style.marginTop = ‘200px’;
change CSS Class to an element
- el.classList.add(‘CSSclassname’);
- el.classList.remove(‘CSSclassname’);
- el.classList.toggle(‘CSSclassname’);