Display a HTML table when hovering over text

I am looking to display a table when hovering over text, and I have implemented this basic jquery/CSS code:

<meta charset="utf-8" />
<title></title>
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script><script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link href="/resources/demos/style.css" rel="stylesheet" />
<script>
  $(function() {
    $( document ).tooltip();
  });
  </script>
<style type="text/css">
label {
    display: inline-block;
    width: 5em;
  }</style>
<p>
    <a href="#" title="I want the below table to be hovered here">Table</a> to be hovered</p>

This is the HTML table that should appear on hover:

HTML:

<table border="4" bordercolor="black" cellpadding="15px" cellspacing="1" style="width: 800px;">
    <tbody>
        <tr>
            <td>
                <h1>
                    <b style="list-style-type: disc; margin-left: 25px; margin-right:5px">This is my table</b></h1>
                <ul style="list-style-type: disc; margin-left: 40px; margin-right:5px">
                    <li>
                        <h1>
                            This is my first point</h1>
                    </li>
                    <li>
                        <h1>
                            This is my second point</h1>
                    </li>
                </ul>
            </td>
        </tr>
    </tbody>
</table>

I have attempted replacing the placeholder text with the HTML table, but it's not functioning as expected. Any suggestions on how to properly call and display the table?

Answer №1

Here's a simple way to achieve this: within your Html code, assign an Id to an element like so:

<a href="#" id="myHoverTitle" title="I want the below table to be hovered here">Table</a>

Next, give your table a second Id and hide it by adding the style attribute with display:none property:

<table id="myContentHover" border="4" bordercolor="black" cellpadding="15px"
       cellspacing="1" style="width: 800px;display:none">
    <!-- Your table content -->
</table>

Lastly, utilize the Jquery toolTip function to show your table when hovering over "myHoverTitle":

$(function() {
    $( '#myHoverTitle' ).tooltip({ content: $('#myContentHover').html() });
});

This JavaScript feature creates a tooltip for "myHoverTitle" using the content of "myContentHover"! Refer to the official JQueryUI tooltip documentation here.

You can also remove the unnecessary content from the title attribute of the element, making it cleaner:

<a href="#" id="myHoverTitle" title="I want the below table to be hovered here">Table</a>

Change it to:

<a href="#" id="myHoverTitle" title="">Table</a>

I hope this explanation was helpful.

Answer №2

An Easy Way to Hide and Show a Table

</script>

// Begin by wrapping the table in a div with an id of 'hide_this_table'
$('#hide_this_table').hide();

// Add hover event
$('#some_text_id').hover(function() { 
    $('#hide_this_table').show();
}, function() {                      
    $('#hide_this_table').hide();
});

</script>


<p id='some_text_id'>Click here to reveal the hidden table</p>

<div id="hide_this_table"> 
    <table>
        <tr>
            <th>Gender</th>
            <th>Date of Birth</th>
        </tr>
        <tr>
            <td>Male</td>
            <td>1995</td>
        </tr>
    </table>
</div>

Give it a try...

Answer №3

adjust your JavaScript code:

$(document).ready(function(){
    $("#demoTable").hide();
    $( "#demo" ).mouseover(function() {
        $("#demoTable").show();
    });
    $( "#demo" ).mouseout(function() {
        $("#demoTable").hide();
    });
});

also, make sure to give an id to the anchor tag and the table, then enclose them in a div element as shown below:

<div>
    <p><a id="demo" href="#" title="Hover over me to see the table below">Click Here</a> to reveal the hidden table</p>
    <table id="demoTable" border="4" bordercolor="black" cellpadding="15px" cellspacing="1" style="width: 800px;">
        <tbody>
            <tr>
                <td>
                    <h1><b style="list-style-type: disc; margin-left: 25px; margin-right:5px">This is the table content</b></h1>
                    <ul style="list-style-type: disc; margin-left: 40px; margin-right:5px">
                        <li>
                            <h1>First Point of Interest</h1>
                        </li>
                        <li>
                            <h1>Second Point of Interest</h1>
                        </li>
                    </ul>
                </td>
            </tr>
        </tbody>
    </table>
</div>

Answer №4

Revise your JavaScript code in the following manner

$.widget("ui.tooltip", $.ui.tooltip, {
    options: {
        content: function () {
            return $(this).prop('title');
        }
    }
});

$(function () {
    $('.tblhover').attr('title', $('.tblcontent').remove().html())
    $(document).tooltip();
});

Subsequently, assign classes to the (anchor tag and table tag) as seen in the HTML snippet below

<a class="tblhover" href="#">Hover over me</a>
<table class="tblcontent" border="4" bordercolor="black" cellpadding="15px" cellspacing="1">
     <tbody>
         <tr>
             <td>
                 <h1><b style="list-style-type: disc; margin-left: 25px; margin-right:5px">This is my table</b></h1>
                 <ul style="list-style-type: disc; margin-left: 40px; margin-right:5px">
                     <li>
                         <h1>Here is the first point</h1>
                     </li>
                     <li>
                         <h1>Here is the second point</h1>
                     </li>
                 </ul>
             </td>
         </tr>
     </tbody>
 </table>

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

Issues with positioning divs in the header and main sections

I'm struggling with positioning the divs inside the header div on my page that has 3 parent divs. Here is a snippet of my code: Divs layout: <div id="layout"> <div id="header" class="body"> header <div id="logo"> ...

Unexpected issue with Ionic 4 subarray returning as undefined even though the index is accurate

When attempting to use console.log to view the value, I noticed that the value of noticeSet2[index] is undefined. However, when I print noticeSet, all the data in the array is displayed. Additionally, after printing the index using console.log, it correctl ...

Experiencing issues on the live server as it appears that Bootstrap is not functioning properly

I am facing an issue with my website where it appears distorted when launched on a live server, despite working fine locally. It seems that the Bootstrap styles are not being applied correctly on the live server and I cannot figure out why. If anyone knows ...

Challenge with AngularJS ng-select and ng-switch-when functionality

Struggling with implementing a selection menu on my angular charts, I encountered some challenges. The selection app template I used only displays the selection menu and graph axis on the page. Checking the console log for errors, I noticed one src URL wa ...

Unlocking the Power of refs in React's this.props.children

Wondering if it's possible to call a function of a child component in React by accessing refs from this.props.children. var ComponentSection = React.createClass({ componentDidMount: function() { // Need to find a way to access refs in this ...

Troubleshooting Bootstrap Column Display Issues on Mobile Devices

I used bootstrap columns to organize my users' information. While they look good on larger screens like laptops and desktops, on smaller phone screens the second column appears to have some excess margin at the top. How can I fix this issue? <div ...

Container that can be scrolled under varying heights

Trying to structure some CSS in order to create a website that resembles the layout of a typical desktop application: Almost there, but struggling to make the scrollable panel stick to the bottom of the viewport and show a scrollbar instead of overflowing ...

Is it possible to retrieve the decimal value from the KendonumericTextbox?

Is there a way to retrieve the decimals and format properties value? var mileagerate = $("#mileagerate").kendoNumericTextBox({ decimals: 2, format: "c2", min: 0.00, step: 0.01 }).data("kendoNumericTextBox"); I'm looki ...

Is it possible to utilize Angular validation directives programmatically within a personalized directive?

In my exploration of HTML inputs, I have noticed a recurring pattern specifically for phone numbers: <input type="text" ng-model="CellPhoneNumber" required ng-pattern="/^[0-9]+$/" ng-minlength="10" /> I am interested in developing a unique directiv ...

Setting the parent's height to match one of its children

I'm struggling to align the height of the pink '#images-wrap' with the main image. When there are too many small rollover images on the right, it causes the pink div to extend beyond the main image's height. If I could make them match i ...

Deactivate a feature by clicking on it

HERE IS WHERE YOU CAN VIEW MY JSFIDDLE On my website, I have a main home page with a smooth scroll wheel script implemented. Additionally, I have a 'about' div that becomes visible when a button is clicked. The issue I am facing is that I want t ...

Determine a specific value in a JSON array of objects and retrieve a different value using Angular

Is there a way to search through my JSON data to locate two specific key values, for example weight = "8m" and meters = "7t", and then retrieve the name value of the object where these two values match, for instance "25t"? Here is a snippet from data.json ...

Loading a basic content snippet dynamically within a view

After following this tutorial, I successfully created a simple functionality: clicking on a button to load content stored in a partial. My intention is to utilize this technique in various scenarios where I want to maintain lightweight views without clutte ...

Why isn't the background image showing up on iOS devices when using the slider?

The website's background image displays on all devices such as laptops and Android phones, but not on iOS mobile devices. I even resized the image to 768px * 365px, but it still doesn't work. .bg-img { position: absolute; left: 0; ...

Using a function as a parameter in Typescript: Anticipated no arguments, received 1.ts

I'm encountering an issue when trying to pass the doSomething function into performAction. The error message I'm receiving is Expected 0 arguments, but got 1 interface SomeInterface { name: string, id: string } function doSomethingFunction( ...

The ios browser environment is unable to retrieve the value during vuejs development

When using vuejs components to create a countdown component, everything seems normal in the pc and Android environments. However, in the iOS environment, there seems to be an issue with obtaining the real count calculation as it returns NaN. <templ ...

Jquery Image Slider showcasing a variety of image sizes

I am in need of creating an image slider that includes images of varying heights. My goal is to ensure there are no gaps between the images. Should any image be smaller, it should be displayed with suitable padding or margin. The image s ...

Unfortunately, I am currently unable to showcase the specifics of the items on my website

I am trying to create a functionality where clicking on a product enlarges the image and shows the details of the product as well. While I have successfully implemented the image enlargement, I am facing challenges in displaying the product details. Below ...

Tips for verifying that jQuery is functioning correctly and that the Jquery.min.js file has been properly loaded

My code usually functions correctly, but occasionally when I input data into the database, it returns output as JSON. Most of the time, the response contains "success" in JSON format, but sometimes I receive the complete JSON output. I have two main pages ...

What is the best way to align the input within the space between the buttons using Bootstrap 5?

I have been trying to center the input between the two buttons but nothing seems to work:( Here is a snapshot of the current layout, I am looking to make it smaller and position it in a single line. https://i.sstatic.net/ggZJR.png <!-- Bootstr ...