Table Row And Column Highlight On Hover Using JavaScript
Submitted by alpha_luna on Tuesday, April 19, 2016 - 17:01.
In this article, we are going to learn Table Row And Column Highlight On Hover Using JavaScript. The table row and column will be highlighted when the mouse hovers it. With the help of a script, this would be easy for us. So, let's try.
Table Form - HTML
This is the table where the user hovers it to highlighting the row and column.
The Script
This script will help us to do the function.
And, this is the style.
Output:
The user mouse hovers to the table row side.
The user mouse hovers to the table column side.
So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.
- <script src="js/code_js.js"></script>
- <script src="js/code_js1.js"></script>
- <script>
- $(document).ready(function() {
- $('.table-row').hover(function() {
- $(this).addClass('current-row');
- }, function() {
- $(this).removeClass('current-row');
- });
- $("th").hover(function() {
- var index = $(this).index();
- $("th.table-header, td").filter(":nth-child(" + (index+1) + ")").addClass("current-col");
- $("th.table-header").filter(":nth-child(" + (index+1) + ")").css("background-color","blue")
- }, function() {
- var index = $(this).index();
- $("th.table-header, td").removeClass("current-col");
- $("th.table-header").filter(":nth-child(" + (index+1) + ")").css("background-color","red")
- });
- });
- </script>
- <style type="text/css">
- body {
- width:700px;
- margin:auto;
- }
- .current-row {
- background-color:pink;
- cursor:pointer;
- color:#FFF;
- font-size:20px;
- }
- .current-col {
- background-color:skyblue;
- color:#FFF;
- cursor:pointer;
- font-size:20px;
- }
- .tutorial-table {
- width: 100%;
- font-size:18px;
- border: blue 1px solid;
- border-spacing: initial;
- margin: 20px;
- word-break: break-word;
- table-layout: fixed;
- cursor:pointer;
- }
- .tutorial-table th.table-header {
- background-color: white;
- text-align: center;
- padding:10px;
- cursor:pointer;
- }
- .tutorial-table .table-row td {
- padding:10px;
- cursor:pointer;
- }
- </style>
![Row](https://www.sourcecodester.com/sites/default/files/col.png)
![Column](https://www.sourcecodester.com/sites/default/files/row_0.png)
Add new comment
- 196 views