Here is my jQuery plugin:
(function($) {
'use strict';
$.fn.tooltipOnOverflow = function() {
$(this).on("mouseenter", function() {
if (this.offsetWidth < this.scrollWidth) {
$(this).attr('title', $(this).text());
} else {
$(this).removeAttr("title");
}
});
};
})(jQuery);
Usage:
$("td, th").tooltipOnOverflow();
Edit:
I have made a gist for this plugin. https://gist.github.com/UziTech/d45102cdffb1039d4415