Conditional Matches

We can tell if it’s single or multiple by looking at the HTML code.

If you mean how can the code tell that it’s single or multiple, it doesn’t. Instead, when we use querySelectorAll to get an array-like list of elements in an object called a nodeList.

When we do var buttons = querySelectorAll(...) that buttons variable ends up being a nodeList.

We can use forEach to iterate over each of the elements in that nodeList. If there is only one element in that nodeList then it doesn’t care, it just does that one item, but would be capable of doing multiple ones if they existed too.

1 Like