JSFiddle - React, Tailwind, and code Playground

by ctrlfrk

HTML

<div>test</div>

JavaScript

//This doesn't actually run, so you can have it outside the ready handler
var Module = (function(){
    var addHandler = function(){
        $("div").click(function(){alert("hi");});
    };
    
    return {addHandler:addHandler};
}());

//This line does nothing, because the DOM hasn't loaded yet so the $("div") is empty
Module.addHandler();


//This line DOES do something, because it is only run once the DOM is loaded.
$(document).ready(function (){
    Module.addHandler();
});