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

123
Views
Tabla HTML creada con Javascript que no escucha CSS y Scripts

Tengo el siguiente código que representa una HTML Table y, después de hacer clic en el botón, onClick una HTML Table más.

El problema es que la segunda tabla no escucha la Función aplicada a la primera tabla que resalta las celdas.

Estoy tratando de averiguar si hay algo que impide que la segunda tabla también escuche el código del script.

Cualquier idea sería muy apreciada.

El estilo CSS es:

 table,tr,th{ border:2px solid black; } table{ width:200px; height:200px; } th.highlight { background-color: black; }

La tabla HTML se ve así:

 <table id="test"> <tr><th>test</th><th>test</th><th>test</th></tr> <tr><th>test</th><th>test</th><th>test</th></tr> <tr><th>test</th><th>test</th><th>test</th></tr> </table> <div id="test2"> </div> <button type="button">Add</button>

Y el Script que se aplica a la primera tabla pero no funciona en la segunda:

 const addColumn = () => { var x = document.getElementById("test2"); x.innerHTML = "<table> <tr><th>test2</th><th>test2</th><th>test2</th></tr> <tr> <th>test2</th><th>test2</th><th>test2</th></tr> <tr><th>test2</th><th>test2</th> <th>test2</th></tr></table>"; } document.querySelector('button').onclick = addColumn $('th').hover(function() { $(this).addClass('highlight'); }, function() { $(this).removeClass('highlight'); });
about 4 years ago · Juan Pablo Isaza
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!