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

137
Views
How to use onmousedown with grid in a for loop javascript

I am trying to get a right-click event to be used with grid in a for loop... I'm not sure if I can use onmousedown in a for loop? please check my code...

document.addEventListener("contextmenu", function (e) {
        e.preventDefault();
    }, false);

for (var i = Math.max(cellRow - 1, 0); i <= Math.min(cellRow + 1, 9); i++) {
  for (var j = Math.max(cellCol - 1, 0); j <= Math.min(cellCol + 1, 9); j++) {
    grid.rows[i].cells[j].onmousedown = function (event) {
      if (event.which == 3) {
        grid.rows[i].cells[j].innerHTML = "f";
      }
    }
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Play with e.target to get what you need.

document.addEventListener("contextmenu", function (e) {
        e.preventDefault();
        console.log(e.target.textContent);
    }, false);

You dont need this part:

grid.rows[i].cells[j].onmousedown = function (event) {
      if (event.which == 3) {
        grid.rows[i].cells[j].innerHTML = "f";
      }
    }

http://jsfiddle.net/RFFy9/

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!