0
<div ref={location} className={style.locations}>
        {locations.map(loc => (
          <span onClick={onClick}>
            {loc.name}
          </span>
        ))}
</div>

I want to access the <span> inside the <div> with "location" ref:

const span = location.current.getElementsByTagName("span");
span.forEach(el => {
   el.style.display = "none";
})

But I just get error:

span.forEach is not a function
Kevin Bryan
  • 1,846
  • 2
  • 22
  • 45

1 Answers1

1

Try this

[...span].forEach(el => {
   el.style.display = "none";
})
iamhuynq
  • 5,357
  • 1
  • 13
  • 36