Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all html nodes have a "getElementsBy" and getElementBy" version?

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?

like image 705
calvincoxiii Avatar asked Aug 07 '17 20:08

calvincoxiii


1 Answers

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
like image 56
Rounin - Glory to UKRAINE Avatar answered Nov 14 '22 20:11

Rounin - Glory to UKRAINE