JSFiddle - React, Tailwind, and code Playground

by xmajox

HTML

<p class="acceptClicks" id="fn1">This should trigger function 1</p>
<p class="acceptClicks" id="fn2">This should trigger function 2</p>
<p id="fn1">This should not trigger any function</p>

CSS

p.acceptClicks { cursor: pointer; }

JavaScript

var test = {};
test.someNameSpace = {};

test.someNameSpace.fn1 = function(someParam){
    alert("Got into function 1 with param '"+someParam+"'");
};
test.someNameSpace.fn2 = function(someParam){
    alert("Got into function 2 with param '"+someParam+"'");
}
$(document).ready(function(){
    $(".acceptClicks").on("click",function(){
        var func = $(this).attr("id");
        console.log(func);
        eval("test.someNameSpace."+func+"("+$this.attr("html")+")");
            
    });    
    }    
);