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

226
Views
¿Cómo configuro un evento de clic para cada celda que llama a una función que toma la identificación de la celda como parámetro en JavaScript?

Aquí creé una tabla y asigné a cada celda una identificación. Lo que quiero hacer es algo como esto cell1.onclik = MyFunction(this.id);

 function createTable() { var table = document.getElementById("tabela2"); for (let j = 0; j < k; j++) { var row = table.insertRow(0); for (let i = 0; i < l; i++) { var cell1 = row.insertCell(0); cell1.id = "celica" + i + "_" + j; /*doesnt work: cell1.onclik = MyFunction(this.id); */ } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No uses eventos onXXX. No funcionará si hay una política de seguridad de contenido en la página.

Solo necesitas escuchar la mesa.

 function createTable() { var table = document.getElementById("tabela2"); // document.body.appendChild(table); for (let j = 0; j < 4; j++) { var row = table.insertRow(0); for (let i = 0; i < 4; i++) { var cell1 = row.insertCell(0); cell1.textContent = "1"; cell1.id = "celica" + i + "_" + j; } } table.addEventListener("click", function(e) { console.log(e.target.id); console.log(e.target.tagName); }); } createTable();
 <html><body><table id='tabela2'></table></body></html>

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!