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

209
Views
¿Cómo hago un detector de eventos (onclick) para una sola celda de tabla?

Mi pregunta es: ¿Cómo puedo hacer que una celda de tabla, por ejemplo, cambie el texto al hacer clic? Intenté esto:

 function randomFunction() { document.getElementById("randomId").innerText = "random text" }
 <table> <tr> <td id="randomId" onclick="randomFunction()">random text</td> </tr> </table>

Pero hace el atributo onclick para toda la fila.

¿Es posible activar la función solo cuando hago clic en la celda?

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

0

Sí es posible. tienes que pasar el contexto a la función. Puse más celdas en tu tabla.

 function randomFunction(e){ e.innerText = "HuhU" // document.getElementById("randomId").innerText = "random text!" }
 td { background: green; color:white; }
 <table> <tr> <td id="randomId" onclick="randomFunction(this)">random text</td> <td id="randomId" onclick="randomFunction(this)">random text</td> <td id="randomId" onclick="randomFunction(this)">random text</td> </tr> </table>

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!