Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
Cannot access textContent of HTML el but can console log it

so i am trying to manipulate with table on this website.

my script i insert in the chrome/firefox console on the website:

let skins = [
"button" //simplified 
];

skins.forEach((skin)=>{

document.querySelector("tbody").childNodes.forEach((k,i)=>{
if(i>0){ // starts with 1 because i==0 is #text
    
    console.log(k.childNodes[1].textContent); // this works in chrome,firefox
    
    let h = k.childNodes[1].textContent; 
    if(h == "shades") console.log("yes"); // this part doesnt work - error 
}
})

});

when i console.log it, it does work, and show all the <tr> on position 1. But when i try to do some code with if statement, the error message shows up,

 Cannot read properties of undefined (reading 'textContent')
at <anonymous>:11:30
at NodeList.forEach (<anonymous>)
at <anonymous>:8:44
at Array.forEach (<anonymous>)
at <anonymous>:6:7
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You are missing {}

if(h == "shades") console.log("yes")

do instead:

if (h == 'shades') {
 console.log("yes");
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Sorry, i didnt carefully set the boundaries, thats why i get an error. There was another #text and the results also needed .trim() to remove extra whitespace.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda