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

232
Views
Al intentar obtener HTML interno, el resultado siempre es indefinido

Estoy generando algunos div y agregando al DOM con esta función

 //Run forEach method on newObj(cats from local storage) to populate and append template to the DOM function getTheCats() { //Limiting the results to 3. Probably better way to do this. newObj.slice(0, 3).forEach(cat => { const catEl = document.createElement('div') catEl.classList.add('cat-detail') catEl.innerHTML = ` <div class="img-id-container" id="pointer-control" onclick="getCatDeets()"> <img class='cat-image' src='${cat.thumbnail_url}' alt="Cat Pic"/> <h3 class="id-left">Cat ${cat.id}</h3> </div> <p class="birthday-left">${cat.birthdate}</p> ` mainLeft.appendChild(catEl) }) } getTheCats()

Estoy tratando de iniciar sesión en la consola, algunos de los HTML internos cuando hago clic en uno de los resultados. Siempre obtengo 'indefinido' como resultado. Sé que me estoy perdiendo algo, pero parece que no puedo averiguar qué. Cualquier ayuda sería muy apreciada.

 function myFunction(event) { const clickedCat = event.target.nodeName; console.log(clickedCat); const details = clickedCat.innerHTML console.log(details) }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

De David784 en los comentarios,

Innecesariamente agregué .nodeName a event.target. Lo reemplacé con .innerHTML y puedo recuperar los datos que necesito.

 function myFunction(event) { const clickedCat = event.target.innerHTML; console.log(clickedCat); const details = clickedCat.innerHTML console.log(details) }
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!