Skip to main content

getElements

getElements has a bit more of an actual use compared to getElement. When you use document.querySelectorAll you get back a NodeList which is very different to an Array in JavaScript.

A NodeList doesn't have a lot of methods that an Array does. You can run in to a lot of friction when using document.querySelectorAll unless you're familiar with this.

This is why getElements was born. What this does under the hood is convert the NodeList you would normally get back into an Array.

Usage examples​

Basic​

const myElements = window.BAO.utils.getElements('.validCssSelector')

Within context​

const header = window.BAO.utils.getElement('header')
const myElementsWithinTheHeader = window.BAO.utils.getElements('.validCssSelector', { context: header })