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?
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.
Select your table visual. Go to the paint roller icon (format). Scroll down and turn on Tool Tip.
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).
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" .
$(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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With