JSFiddle - React, Tailwind, and code Playground

by Adam Poczatek

JavaScript

(function( $ ){

    var methods = {
        { init : function( options ) { alert(options) } },
        show : function( ) {},
        hide : function( ) {},
        update : function( content ) {}
    };
    
    $.fn.tooltip = function( method ) {
    
        // Method calling logic
        if ( methods[method] ) {
            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
        }    
    
    };

})( jQuery );
        
$(function() {
    $('body').tooltip('init', 'My message!');
    $('body').tooltip({ init : 'My message 2!' });
})