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

189
Views
How do I select multiple rows in an html table by pressing ctrl key or shift key?

I have a simple html table where the rows are dynamically created and values are inserted into the cells. This is the code:

var table=document.getElementById("emp");

var row=table.insertRow(0);
var cell = row.insertCell(0);
var cell1 = row.insertCell(1);
var cell2 = row.insertCell(2);
cell.innerHTML="<b>Name:</b>";
cell1.innerHTML="<b>Age:</b>";
cell2.innerHTML="<b>Address:</b>";

var row1=table.insertRow(1);
var cell3=row.insertCell(0);
var cell4=row.insertCell(1);
var cell5=row.insertCell(2);
cell3.innerHTML="Alex";
cell4.innerHTML=23;
cell5.innerHTML="Chicago";

Now, I want to be able to select multiple rows in my table, using the Ctrl or Shift. How do I do that? Please help me.

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

0

You can check inside your click handler if a key is pressed and if so, perform the appropriate action

const trs = document.querySelectorAll('tr');
trs.forEach(tr => tr.addEventListener('click', (e) => {
    console.log(e.shiftKey); // Will print true if shift is pressed.
}))
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!