Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a Tooltip to a "td" with jquery?

Tags:

html

jquery

I need to add a tooltip/alt to a "td" element inside of my tables with jquery.

Can someone help me out?

I tried:

var tTip ="Hello world";
$(this).attr("onmouseover", tip(tTip));

where I have verified that I am using the "td" as "this".

**Edit:**I am able to capture the "td" element through using the "alert" command and it worked. So for some reason the "tip" function doesn't work. Anyone know why this would be?

like image 517
SpoiledTechie.com Avatar asked Oct 03 '08 04:10

SpoiledTechie.com


People also ask

How do I add tooltip to TD?

To create a tooltip add bootstrap libraries to your code. Add the data-toggle="tooltip" atribute to an element. Add your description in the title atribute. In the above code, I've used tooltip in a <td> element.

How do I add a tooltip to a table?

Select your table visual. Go to the paint roller icon (format). Scroll down and turn on Tool Tip.

How do I add a tooltip to a row?

All it is is a simple HTML element styled with CSS such that it displays itself whenever you hover over its parent element. So, wherever you want there to be a tooltip, you'll need to add that class="tooltip" div (and its child span element).

How do I add a tooltip to an element?

Basic Tooltip HTML: Use a container element (like <div>) and add the "tooltip" class to it. When the user mouse over this <div>, it will show the tooltip text. The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" .


1 Answers

$(this).mouseover(function() {
    tip(tTip);
});

a better way might be to put title attributes in your HTML. That way, if someone has javascript turned off, they'll still get a tool tip (albeit not as pretty/flexible as you can do with jQuery).

<table id="myTable">
    <tbody>
        <tr>
            <td title="Tip 1">Cell 1</td>
            <td title="Tip 2">Cell 2</td>
        </tr>
    </tbody>
</table>

and then use this code:

$('#myTable td[title]')
    .hover(function() {
        showTooltip($(this));
    }, function() {
        hideTooltip();
    })
;

function showTooltip($el) {
    // insert code here to position your tooltip element (which i'll call $tip)
    $tip.html($el.attr('title'));
}
function hideTooltip() {
    $tip.hide();
}
like image 134
nickf Avatar answered Sep 23 '22 22:09

nickf