Reputation: 1610
I have a table in which the cells show ellipsis if too long. I set overflow: hidden and text-overflow: ellipsis on the td elements.
I now need to show a tooltip if the user hovers a cell that can't fit the entire text, but no tooltip on other cells.
I can register an event to capture mouseover, but how can I tell if the hovered td shows ellipsis or not?
Upvotes: 2
Views: 283
Reputation: 537
You can check the scrollWidth of the content and compare it to the width of the element. Here's a solution with jQuery:
$('td').each(function () {
if ($(this)[0].scrollWidth > $(this).innerWidth()) {
// Text is overflowing
}
});
Upvotes: 2