"Revealing the specific row and column of the selected element in each table when hovering over it

On my webpage, I have set up two tables positioned side by side like this:

<!DOCTYPE html>
    <table>
        <tr>
            <td>
                <table>
                    <tr><td>1</td><td>2</td><td>3</td></tr>
                    <tr><td>4</td><td>5</td><td>6</td></tr>
                    <tr><td>7</td><td>8</td><td>9</td></tr>
                </table>
            </td>
            <td>
                <table>
                    <tr><td>1</td><td>2</td><td>3</td></tr>
                    <tr><td>4</td><td>5</td><td>6</td></tr>
                    <tr><td>7</td><td>8</td><td>9</td></tr>
                </table>
            </td>
        </tr>
    </table>

Whenever I hover over a cell in either table, I want the corresponding cell in the other table to also be highlighted at the same time (for example, hovering over [0,0] should highlight [0,0] in the other table).

To achieve this effect for one table, I followed the guidance in this link (using addClass and removeClass instead of toggleClass). How can I extend this functionality to cover both tables?

Answer №1

Here's a technique to achieve this task, it would have been simpler if the tables were given IDs but this approach will do as well:

$('table table td').hover(function() {
    $this = $(this);
  $this.toggleClass('hovered');
    //identifying the selected cell
    cell = $this.closest("table").find("td").index(this);
   $this.closest("table").parent().siblings("td").find("td").eq(cell).toggleClass('hovered');
});

http://jsfiddle.net/rhyu3r0r/1/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

eliminate the script and HTML comment from a designated division

Here is the default code that I need to modify using JavaScript to remove scripts, comments, and some text specifically from this div: I came across this script that removes all scripts, but I only want to remove specific ones from this div: $('scri ...

Troubleshooting Problem with HTML Links in jQuery Accordion

After experimenting with adding a link to the HTML section of the accordion, I discovered that the link appears bold and does not open. I attempted to create a class or ID to fix this issue, but my efforts were unsuccessful. http://jsfiddle.net/q2Gm9/ ...

Issues with Bootstrap column rendering in IE11's Flex layout

I need assistance with the code below: .hero{ background:lightgrey; padding: 50px 0px; } <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E26 ...

Jquery with horizontal scroll feature

I am having an issue with my horizontal scroll feature. Despite inspecting in Chrome and finding no errors, I still cannot locate the problem. Can someone please help me identify where the issue lies? <html> <head> <script src="http ...

Is there a way to obtain a comprehensive list of zip codes that are traversed by your route directions?

I have been searching through the Google Maps API (both Android and Web) but have not come across any references on how to retrieve a list of all the zip codes that are traversed by a given driving route. Could it be possible that I am missing something, ...

Ways to align the content in the middle of a div with CSS

My website is functioning perfectly on large devices, but I am facing an issue when trying to center the icon below the slider on mobile devices. I have used the following code in the icn class: .icn{ margin:0 auto; } However, the icon is not centered as ...

How can I restrict the number of items displayed in each row within a navigation submenu flexbox?

My primary navigation menu has numerous child items, and I want to ensure they remain visually appealing and organized. To achieve this, I am aiming to limit each row of submenu items to only 4. After researching other solutions online, I attempted adding ...

What is the best way to show an element when hovering over another element?

I'm looking for a CSS-only solution (NO JQuery) to display a FontAwsome icon (<i class='fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success hidearrowbounce'></i>) only when hovering over another element. However, despite ...

Exploring the Power of Selenium in Python: Automating the Clicking of Expand Links Without Identifiers

Struggling to fill out a form in IE9 using Selenium and Python. The form is loaded with 'Expand/Collapse' links, all identical except for the text labels. No ID on them, just 'style' and 'onclick' attributes (though there migh ...

Why does it appear that Angular is undefined in this straightforward Angular demonstration?

I'm completely new to AngularJS and I've encountered an issue. Yesterday, I ran a very simple AngularJS application that I downloaded from a tutorial and it worked perfectly. The application consists of 2 files: 1) index.htm: <!DOCTYPE htm ...

Navigating through ajax requests on a Leaflet map

Currently, I have a leaflet map set up with the leaflet-panel-layers plugin to create a visually appealing layer control. To create my layers and overlays, I have two functions in place. The issue arises when trying to access external geoJSON files, as lea ...

What is the best way to align this image in the center?

I've been struggling with this problem for a while now and can't seem to find a solution. I need to center align this image within the form, but everything I've tried so far has been unsuccessful. It may seem like I'm providing too much ...

What is the best method for loading multiple HTML files into a Div container?

Recently, I made the decision to improve the look of an online manual I have been working on for my company by incorporating Bootstrap. The manual is structured with a tree-view that contains titles linking to HTML files with information and CSS stylesheet ...

Identify specific elements using CSS to easily target them with JavaScript later on

Currently, I am utilizing CSS selectors to target specific elements and now I want to be able to identify those elements using javascript. My approach involves setting the color of these elements in css and then retrieving them based on their color. Howeve ...

AngularJS and Spring Rest team up for seamless drag-and-drop file uploads

I have successfully implemented file upload using AngularJS and Spring REST, but now I want to change it to use dropzone.js or any other drag and drop file upload method. I tried using the dropzone.js library, but I am facing issues integrating it with Ang ...

Any tips on how to retrieve parameters from a $.post request?

After learning about $.post, I have both PHP and HTML code that I'm working with. My goal is to later utilize specific elements from the result array, such as FileName and Width. How can I achieve this? Here is the PHP code snippet: <?php $jso ...

Display 5 div elements as the user scrolls down the page using jQuery

In my page, I have a total of 10 divs. The first div is visible while the rest are hidden. div1,div2,div3----div10 As the user scrolls down the page, I want to reveal 5 divs. div2----div6 div7---div12 (although div12 doesn't actually exist, I' ...

Struggling with jQuery fadeIn and fadeOut in IE8?

I am struggling to understand why my fadeIn, fadeOut, and corner() functions are not working in IE8 on my website at . They were functioning properly before, but now they seem to be broken. Can anyone pinpoint the issue causing this problem? If you click ...

Could using an image defer script instead of a lazy image script result in an undefined offset error?

To enhance the pagespeed of my website, Pagespeed Insight recommends using deferred images instead of lazy jQuery images. In an effort to follow this advice, I made adjustments based on suggestions from another source. Read more on stackoverflow I utiliz ...

Updating content dynamically in a MVC div element using AJAX

Working on an MVC application, I encountered a situation where I need to refresh a section of the page using AJAX... <div id="ajax" style="width:10%;float:left"> @foreach (var item in @Model.SModel.Where(x=>x.StudentId==13)) { <li>@Html.Dis ...