Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!