Given an HTML table and the task is to add a tooltip to the table cell without using JavaScript. There are two methods to solve this problem which are discussed below:
Approach 1:
- Create a HTML table.
- Add title attribute (title = “someTitle”) to the table cell to add tooltip.
Example 1: This example implements the above approach.
<!DOCTYPE HTML> <html> <head> <title> How to add tooltip to HTML table cell without using JavaScript ? </title> <style> #MyTable{ border: 1px solid black; } #MyTable td{ border: 1px solid black; padding: 3px; } </style> </head> <body align = "center"> <h1 style = "color:green;" > GeeksForGeeks </h1> <p id = "GFG_UP" style = "font-size: 15px; font-weight: bold;"> </p> <center> <table id="MyTable"> <thead> <tr> <td>Attr 1</td> <td>Attr 2</td> <td>Attr 3</td> </tr> </thead> <tbody> <tr> <td title="1, 1">1, 1</td> <td title="1, 2">1, 2</td> <td title="1, 3">1, 3</td> </tr> <tr> <td title="2, 1">2, 1</td> <td title="2, 2">2, 2</td> <td title="2, 3">2, 3</td> </tr> </tbody> </table> </center> <script> var el_up = document.getElementById('GFG_UP'); el_up.innerHTML = "Hover over the cells " + "to see the tooltip."; </script> </body> </html> |
chevron_right
filter_none
Output:
-
Before hovering over the cell:
-
After hovering over the cell:
Approach 2:
- Create a HTML table.
- Create a <span> element in the table cell in which we want to add a tooltip.
- Initially set the display: none of the <span> element.
- Whenever the user hovers over this particular element, Just change the property to display: block.
Example 2: This example implements the above approach.
<!DOCTYPE HTML> <html> <head> <title> How to add tooltip to HTML table cell without using JavaScript ? </title> <style> #MyTable{ border: 1px solid black; } #MyTable td{ border: 1px solid black; padding: 3px; } .parentCell{ position: relative; } .tooltip{ display: none; position: absolute; z-index: 100; border: 1px; background-color: white; border: 1px solid green; padding: 3px; color: green; top: 20px; left: 20px; } .parentCell:hover span.tooltip{ display:block; } </style> </head> <body align = "center"> <h1 style = "color:green;" > GeeksForGeeks </h1> <p id = "GFG_UP" style = "font-size: 15px; font-weight: bold;"> Hover over the 1, 2 to see the tooltip. </p> <center> <table id="MyTable"> <thead> <tr> <td>Attr 1</td> <td>Attr 2</td> <td>Attr 3</td> </tr> </thead> <tbody> <tr> <td>1, 1</td> <td class="parentCell">1, 2 <span class="tooltip">Tooltip</span> </td> <td>1, 3</td> <tr> <td>2, 1</td> <td>2, 2</td> <td>2, 3</td> </tr> </tbody> </table> </center> </body> </html> |
chevron_right
filter_none
Output:
-
Before hovering over the cell:
-
After hovering over the cell:
Recommended Posts:
- How to add a tooltip to a div using JavaScript?
- How to add table row in a table using jQuery?
- How create table without using <table> tag ?
- How to prevent text in a table cell from wrapping using CSS?
- How to create equal width table cell using CSS ?
- How to wrap table cell <td> content using CSS ?
- How to create table cell using HTML5 ?
- How to create a header cell in a table using HTML5 ?
- How to use complex HTML with twitter Bootstrap tooltip using jQuery ?
- How to remove the table row in a table using JavaScript ?
- How place a checkbox into the center of a table cell?
- Building Tooltip using CSS
- How to Create Link Tooltip Using CSS3 and jQuery ?
- How to create table with 100% width, with vertical scroll inside table body in HTML ?
- How to remove table row from table using jQuery ?
- Bootstrap 4 | Tooltip
- How to enable Bootstrap tooltip on disabled button ?
- jQuery UI | Tooltip
- CSS | Tooltip Fade In Animation
- How to write a cell phone number in an international way using JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


