Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:26:23+00:00 2026-06-09T21:26:23+00:00

I need a pure Javascript (no jQuery) hover effect for HTML table columns. I

  • 0

I need a pure Javascript (no jQuery) hover effect for HTML table columns.

I found this which supposedly contains a fix for Firefox yet it still looks broken to me.

I found this which works only for the first column.

Unfortunately, my Javascript skills are amateur at best, so my attempts to modify either of these turned out to be fruitless.

Is this possible? Any suggestions would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:26:24+00:00Added an answer on June 9, 2026 at 9:26 pm

    Here’s a column-based approach. When the mouse enters/leaves a cell, find the corresponding <col/> by index and apply/remove the desired class:

    (() => {
      const myTable = document.getElementById("myTable");
      const cols = myTable.querySelectorAll("col");
      const events = {
        mouseover: e => {
          const t = e.target.closest("td");
          if (t) {
            const cellIndex = t.cellIndex;
            for (let i = 0, n = cols.length; i < n; i++) {
              cols[i].classList[i === cellIndex ? "add" : "remove"]("hovered");
            }
          }
        },
        mouseout: e => {
          const t = e.target;
          if (t.nodeName === "TD" && !t.contains(e.relatedTarget)) {
            cols[t.cellIndex].classList.remove("hovered");
          }
        }
      };
      for (let event in events) {
        myTable.addEventListener(event, events[event]);
      }
    })();
    .hovered {
      background-color: #FF0000;
    }
    <table id="myTable" cellspacing="0">
      <col />
      <col />
      <col />
      <tbody>
        <tr>
          <td>Col1</td>
          <td>Col2</td>
          <td>Col3</td>
        </tr>
        <tr>
          <td>Col1</td>
          <td>Col2
            <span>nested</span>
          </td>
          <td>Col3</td>
        </tr>
        <tr>
          <td>Col1</td>
          <td>Col2</td>
          <td>Col3</td>
        </tr>
      </tbody>
    </table>

    See also:

    • Element.classList
    • Node.Contains()
    • Element.Closest()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a pure JavaScript equivalent of this Jquery code: because the use of
I need pure javascript function that finds the current opacity of HTML element and
I need a multiple file uploader created by pure jquery/Javascript and php5. Not use
I need that Nhibernate only generate pure SQL, which I will send to my
I need multemethod dispatch with Moose objects. I'm doing this with Class::Multimethods::Pure . I
I need to change the method attribute of my form with javascript (jQuery or
i have a signle html element which i need to show and hide by
This may sound impossible but read on. I need to learn jQuery a little
Does anyone know of a small, limited functionality lightbox built with pure javascript? This
I need to extract pure text form a random web page at runtime, on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.