JSFiddle - React, Tailwind, and code Playground

by jackrugile

HTML

<a href="#" title="Shorter title text">This is the original text, which is longer</a>

JavaScript

(function($){

    $.fn.txtSwap = function() {
        var $this = $(this);
        var title = $this.attr('title');
        var text  = $this.text(); 
        var origWidth = $this.width();
        
        $this.hover(function(){
            $this.text(title).attr('rel', text).removeAttr('title');
            if($this.width() < origWidth){
                $this.css({'display' : 'inline', 'width' : origWidth+'px'});   
            }
        },function(){
            $this.text(text).attr('title', title).removeAttr('rel');
            $this.css({'display' : 'inline', 'width' : 'auto'});
        });
    };
    
})(jQuery);


$(document).ready(function(){
    $('a').txtSwap();
});