JSFiddle - React, Tailwind, and code Playground

by Brad Christie

HTML

<div id="test"></div>

JavaScript

// anonymous function that is executed within the jQuery context
    // to preserve reference in case of $.noConflict
    (function($){
        // $ is now short for jQuery
        // $.fn is short for jQuery.prototype

        // if you want $.myCustomFunction
        $.extend({
            myCustomFunction: function(arg){
                $('#test').append($('<p>').text('myCustomFunction: '+arg));
            }
        });
        
        // or if you want $('...').myCustomFunction()
        $.fn.extend({
            myCustomFunction: function(arg){
                $.myCustomFunction(arg + ' [from selector]');
            }
        });
    })(jQuery);


$('#test').myCustomFunction('Hello, world');
$.myCustomFunction('Foo, bar');