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

393
Views
there is other way to get properties of cell in JS then event.target.nodeName.toLowerCase()?

so I have this problem that I want to compare 2 cells of Chess table that I did. When I click on cell, I'm getting in console.log only td, and the comparison I'm using I have the cell itself (I added photo for example) so there is other way to get the cell properties when click on it then the event.target.nodeName.toLowerCase()?

We can see that in the left lower there is td when i click on cell, and when i click on the cell with "inspect" im seeing the cell itself here in this function im sending cell and try to compare it to event.target.nodeName.toLowerCase() the problem is, that in event.target.nodeName.toLowerCase() i have "td" and not the "cell" like shonw in the right side of the photo, so i want to know if there is other opetion whel im clicking on some cell of grid(chess table) that i can get the cell itself to be compared.

  const handler= Click.bind(null, cell);
    table.addEventListener("click", handler);

    function Click(cell, event) {
        if (event.target.nodeName.toLowerCase() === 'td' )
        {
            event.target.style.backgroundColor = "blue";
            if (event.target.nodeName.toLowerCase() == cell])
            {
                alert("SOMETEXT")
            }
        }
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can get the target element classes with <Element>.classList and after check if it's a black or white cell according to its class.

<DOMTokenList>.contains is one of methods you can use to check if the element has a specific class in a mordern way, thanks to @CerebralFart and @Bergi.

document.onclick = e => {
  const cell = e.target.classList.contains('blackcell')
    ? 'black'
    : 'white';
  console.log(cell);
}
<table>
  <tr>
    <td class="cell blackcell">B</td>
    <td class="cell whitecell">W</td>
    <td class="cell whitecell">W</td>
    <td class="cell blackcell">B</td>
    <td class="cell blackcell">B</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!