JSFiddle - React, Tailwind, and code Playground

HTML

<div id="foo">Foo</div>

<button id="bar">Bar</button>

JavaScript

$(function(){
   function fn(arg){
       console.log(arg);
       var foo = $(this);
       var bar = $('#bar');
       if( foo.text() == 'Foo' ) {
           foo.text('Bar');
           bar.text('Foo');
           return 'Changed to Bar';
       } else {
           foo.text('Foo');
           bar.text('Bar');
           return 'Changed to Foo';
       }
   }
   
    var n = 0;
    $('#bar').click(function(){
        var foo = $('#foo');
        if( $.isFunction( foo.data('fun') ) ){             
            var ret = foo.data('fun').call(foo, ++n);
            console.log('ret: %o', ret);
        }
    });
    
    $('#foo').data('fun', fn);
});