I have a dynamic table, loaded with ajax. I want to show a tooltip when I hover the mouse over a row, but I want the tooltip to appear over a certain cell (with class .name
) instead of above the entire row.
Also, using title function, I need to be able to get closest row id and return a custom template.
Here is my code:
<table class="table" id="myTable">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
<th>Statistics</th>
</tr>
</thead>
<tbody>
<tr id="1">
<td >1</td>
<td class="name">Name #1</td>
<td>United States of America</td>
<td>100%</td>
</tr>
<tr id="2">
<td >2</td>
<td class="name">Name #2</td>
<td>United States of America</td>
<td>50%</td>
</tr>
</tbody>
</table>
Initialization:
<!-- language: lang-js -->$('#myTable').tooltip({
container: 'body',
html: true,
selector: 'td.name',
trigger: 'manual',
title: function() {
// here will be custom template
var id = $(this).parent().atrr('id');
return id;
}
});
Attempt One : Demo in jsFiddle
<!-- language: lang-js -->$('#myTable')
.on('mouseenter focusin', 'tbody > tr', function() {
$(this).find('td.name').tooltip('show');
})
.on('mouseleave focusout', 'tbody > tr', function() {
$(this).find('td.name').tooltip('hide');
});
Attempt Two : Demo in jsFiddle
<!-- language: lang-js -->var tip;
$('#myTable')
.on('mouseenter focusin', 'tbody > tr', function() {
tip = $(this).find('.offer-name');
tip.tooltip(hereAllTooltipOptions);
tip.tooltip('show');
})
.on('mouseleave focusout', 'tbody > tr', function() {
tip.tooltip('hide');
});
But I wonder greatly over the performance of such a solution. So, the question is how to do it and do it better?