Remove the column lines when hovering over a table to change the border color

I'm striving to update this table in a way that conceals the lines above the hovered point within that column. For instance, if the bottom middle box is hovered, three lines above it will be visible. My goal is to prevent those lines from being displayed.

  <table>
      <tr><td></td><td></td><td></td></tr>
      <tr><td></td><td></td><td></td></tr>
      <tr><td></td><td></td><td></td></tr>
      <tr><td></td><td></td><td></td></tr>
      <tr><td></td><td></td><td></td></tr>
  </table>


    <script>
      $('td').on('mouseover mouseout', function(){
             $(this).prevAll().addBack()
             .add($(this).parent().prevAll()
             .children(':nth-child(' + ($(this).index() + 1) +   
       ')')).toggleClass('hover');
         });

  </script>

table {
    table-layout:fixed;
    width:100%;
    height:300px;
    border-collapse:collapse;
      }
 td {
    border:1px solid black;
 }
.hover {
    border-color:#ef7c32; border-width:2px;}

Answer №1

This function will toggle the hover effect on a specific column of cells:

  $('td').on('mouseover mouseout', function(){
     var index = $(this).parent().children().index(this);
     $('table tr').children().eq(index).toggleClass('hover');
  });

The first line locates the position of the hovered cell within its row. The second line toggles the hover class for cells at that position across all rows.

Styling for the hover effect is set as follows:

.hover {
    border-top: none;
    border-bottom: none:
}
table tr:first-child .hover {
    border-top: 1px solid black;
}
table tr:last-child .hover {
    border-bottom: 1px solid black;
}

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

Managing JSON data through AJAX in ColdFusion

For my external API call using AJAX, I am incorporating a local API setup as an intermediate step. The process is as follows: The Ajax call sends data to localAPI.cfm. Within localAPI.cfm, there is a <cfhttp> tag to forward the data to an external ...

At what point are watch variables accessible in the Chrome-Node-Debugger tool?

My test file runs periodically, either every minute or second, depending on how I configure it. https://i.sstatic.net/duXl5.png Despite setting watches on variables in the file, they do not populate as expected: https://i.sstatic.net/W6CFo.png Interest ...

Tips for Implementing jQuery UI Dialog as a Confirmation Dialog for Form Submissions in ASP .NET

I am currently exploring the possibilities of utilizing jQuery UI or a different dialog plugin to replace the default Confirm dialog. While there are numerous similar inquiries and responses on StackOverflow, such as: jquery dialog: confirm the click on a ...

Tips for displaying an alpha-numeric keyboard in a React Native application

I am struggling to display an alpha-numeric keyboard in my React-Native App. I have tried various values for the keyboardType prop, but none of them seem to work for me. If anyone has any suggestions on how I can achieve this, please do share your ideas w ...

Converting an ajax request to CORS

Would appreciate some guidance on accessing an API through my localhost using the code below: $.ajax({ url: "http://domain.xxx.net/api/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7a3b8bcb2b9a4f9bda4b8b9e8b2ba ...

Retrieve the Mongoose constructor information during the pre-save function

I am working with a schema that looks like this: const CustomerSchema = new Schema({ email: { type: String, required: true, unique: true }, flags: { marketingConsent: { type: Boolean, required: true }, }, }); When creating a new customer: co ...

Embed a script tag in Capybara and pause execution until an asynchronous task is finished

Having trouble injecting a script in Capybara. Take a look at the code below: Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, :phantomjs_options => ['--debug=no', '--ignore-ssl-errors=yes' ...

Locate a Checkbox using JQuery and NodeJS

Searching for the presence of a checkbox in a webpage using NodeJS with JQuery (other suggestions are welcome). However, I am struggling to locate the checkboxes within the form. Below is the code snippet from the webpage: <form id="roombookingform" c ...

Why is the React onClick method returning undefined upon the first selection, and why are the values being passed not consistent with

While attempting to create a list of users that, when clicked, should open up a corresponding user's message, I encountered an issue where clicking for the first time resulted in an 'undefined' value being passed. I've tried troublesho ...

The debate between classes and data attributes in terms of auto field initialization

A Brief Background In the realm of javascript/jQuery, I've crafted a method that traverses through various fields and configures them based on their type - be it dropdowns, autocomplete, or text fields... The motivation behind this is my personalize ...

What causes jQuery to add an extra <p></p> when using $("<p>something</p>")?

Encountered an interesting behavior in jQuery that I wasn't aware of before. It happened with the following code: $("<p><div>item1</div></p>") The resulting output is: [<p>​</p>​, <div>​item1​</d ...

Error message: Attempting to call the row() function on a variable that is not an object while trying to

Currently, I am using CodeIgniter for my application development and incorporating jQuery to transmit JSON data. Below is the code snippet: public function updateRequest($id_request, $jenis_request, $keluhan ){ $data= array( 'jenis_r ...

What is the best way to retrieve data from localStorage while using getServerSideProps?

I'm currently developing a next.js application and have successfully integrated JWT authentication. Each time a user requests data from the database, a middleware function is triggered to validate the req.body.token. If the token is valid, the server ...

How to easily transfer a JSON file to a server using Vue and Node.js

As a newcomer to the world of Node.js and Vue development, my goal is to establish a seamless process for users to create and upload a JSON file to the server when they save data in a form. This process should occur effortlessly in the background, allowing ...

Transforming a JavaScript variable into a PHP function call

Looking to transfer a Javascript variable into PHP by replacing the const 4 with var i var ntime = '<?php echo count($czasAr);?>'; for (var i = 0; i < ntime; i++) { ...

Guide to adding customized CSS and JavaScript to a specific CMS page on Magento

I'm trying to incorporate a lightbox for video playback on a specific page of my CMS. I've placed my CSS file in JS/MY THEME/JQUERY/PLUGIN/VENOBOX/CSS/myfile.css and the JS files in JS/MY THEME/jquery/plugins/venobox/js/myfile.js, but it doesn&ap ...

Dynamic forms with live updates in Django

I have a vision for my website where I want to incorporate a dynamic form that can be accessed and updated by multiple users simultaneously. The idea is that as one user makes changes to the form, those updates are immediately visible to all other users wi ...

Laravel 4 Data Cleaning for Improved Security

I am currently utilizing Laravel 4 to establish a RESTful interface for my AngularJS application. Right now, I am looking to update an object within my model named Discount Link. The method I am using involves: $data = Input::all(); $affectedRows ...

What is the best way to sort through the data retrieved using jQuery.ajax()?

When utilizing the jQuery.ajax() method, I'm facing challenges in filtering the returned data to extract exactly what I need. Although it's straightforward with .load() and other jQuery AJAX methods, I specifically require using .ajax(). For ins ...

Avoiding Dropdown Click Propagation in Bootstrap and AngularJS

When using Bootstrap 3 and AngularJS, I have a list group where each item has a dropdown menu aligned to the right. I want it so that when I click on the dropdown, only the dropdown menu is displayed without triggering the "itemSelected" function for the i ...