#Node list returning, followed by Undefined :flushed:

4 messages · Page 1 of 1 (latest)

glass jungle
#

Quick preface: I'm very new to this and working on my first web app for my little sibling.

I'm building the app without a framework because they're out of my scope right now, playing mostly with css and js interactions first

I'm running this function I found in a youtube video to optimize my css changes


var $ = (q) => {
  const els = document.querySelectorAll(q);
  if (els.length > 1) {
    return els;
  } else if (els.length === 1) {
    return els[0];
  }
};

as expected, it's returning a NodeList, and my foreach loop is working properly up until the end, when I'm thrown:

Error: $(thing) is undefined

a quick

console.log($(thing))

returns;

NodeList{0: {…}, 1: {…}}

undefined

What simple error am I not understanding about my function that's causing me to misuse it in my foreach loops?

#

I wanna specify that I'm currently using the function to search for all objects of a specified class, like so:

$('.class_name')
glass jungle
#

I'm so dumb

#

thanks ducks