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

195
Views
Uncaught TypeError: Cannot read properties of undefined (reading 'textContent')

I am trying to get values from a table and i got this error Uncaught TypeError: Cannot read properties of undefined (reading 'textContent') can someone please help to resolve it?

js

 const cards = document.getElementById('cards')
 const templateCarrito = document.getElementById('template-carrito').content

 const fragment = document.createDocumentFragment()
 let carrito = {}

 cards.addEventListener('click', e => {
     addCarrito(e)
 })

const pintarCards = toolList => {
                toolList.forEach(producto => {
                   
                    templateCard.querySelectorAll('td')[0].textContent = producto.tbl_herramienta_ID
                    templateCard.querySelectorAll('td')[1].textContent = producto.tbl_herramienta_NOMBRE
                    templateCard.querySelectorAll('td')[2].textContent = producto.tbl_herramienta_DESCRIPCION
                    templateCard.querySelector('.btn-success').dataset.id = producto.tbl_herramienta_ID
                    const clone = templateCard.cloneNode(true)
                    fragment.appendChild(clone)
                })
                cards.appendChild(fragment)
            }

            // agregar al arrito
            const addCarrito = e => {
                if (e.target.classList.contains('btn-success')) {
                    console.log(e.target.dataset.id)
                    setCarrito(e.target.parentElement)
                }
                e.stopPropagation()
            }

 const setCarrito = objeto => {
                
                const producto = {
                    id: objeto.querySelector('.btn-success').dataset.id,
                    nombre: objeto.querySelectorAll('td')[1].textContent,
                    descripcion: objeto.querySelectorAll('td')[2].textContent,
                    cantidad: 1
                }
                console.log(producto)
   
            }

i got an error in nombre: objeto.querySelectorAll('td')[1].textContent, descripcion: objeto.querySelectorAll('td')[2].textContent,

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

templateCard.querySelectorAll('td') does not seem to give you as many results as you expect, hence the call to .textContent fails (one of three elements seem to be null). You can try to log the results of that selector to see what the resulting elements are.

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!