bloom bloom
bloom bloom

Reputation: 131

How to retrieve the text from a className in react

I am trying to access the words from the className muichip label.

I returned 14 results which are undefined in the console log. But I am not to sure why they are not returning back as a string? Can anyone help me?

 const unitTests = unitTestTemplates.map((item) => {
        console.log(document.getElementsByClassName("MuiChip-label").innerHTML)
          
      }
   

Upvotes: 0

Views: 931

Answers (1)

hgb123
hgb123

Reputation: 14881

document.getElementsByClassName() return a list of elements (doc), so you should iterate through that list

document.getElementsByClassName("MuiChip-label").forEach(function(element) {
  console.log(element.innerHTML)
})

Upvotes: 1

Related Questions