I'm learning vanilla js and something that keeps coming up is that I see some examples of code that say document.getElementBy... or document.getElement(s)By..., Is it the case that every html node has a corresponding js dom form where getElementBy refers to a single node and getElementsBy refers to a nodeList?
Principal element gathering methods from the DOM API are:
document.getElementById('[ID]')
// returns live HTML Element Object
document.getElementsByClassName('[CLASS]')
// returns live HTML Collection Object
document.getElementsByName('[NAME]')
// returns live HTML Collection Object
document.getElementsByTagName('[ELEMENT-TYPE]')
// returns live
HTML Collection Object
and
document.querySelector('[CSS-SELECTOR]')
// returns static HTML Element Object
document.querySelectorAll('[CSS-SELECTOR]')
// returns static NodeList Object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With