JSFiddle - React, Tailwind, and code Playground

HTML

<a href="#one">one</a> <a href="#two">two</a>

JavaScript

function doStuff(){

    //run some code only on the first execution
    alert('execute miscellaneous code once on load');


    function myHandler(){
        alert('myHandler fired');
    }
    
    
    //or just execute the function that gets returned below
    myHandler();

    // return myHandler as the event handler
    return myHandler;

};

$(window).bind('hashchange', doStuff() );