Closed EmilePW closed 4 years ago
This looks great, thanks :) It may also be worth mentioning something like:
If you want to use a NodeList
like an Array (e.g. call .map
on it), you can turn it into an Array like this:
let elementArray = Array.from(document.querySelectorAll("div"));
Then elementArray
will be an Array
containing each of the DOM elements.
Thanks @illicitonion, that's a good point - I've added an Array.from
example in too.
What does this change?
Module: JS2 Week(s): 2
Description
I've changed the description of what
.querySelectorAll
returns to be slightly more accurate - it previously said that it returns an array when it actually returns an array-likeNodeList
which doesn't implement most of the array methods. I hope now it isn't too confusing by introducing an extra concept? My worry was that students might start trying to use.map
, etc. on aNodeList
and be confused when that fails.Rendered version
Who needs to know about this?
@ChrisOwen101