Pass with user data attribute
3 answers
You can do it as follows:
<div data-myattr="hello"></div> function hello(){ console.log('hello'); } function executeFunctionFromData(){ var d = 'hello' // Save `data-myattr` to d; (Obviously, this is just a hardcoded value as an example) window[d](); // Execute the function. } This works because the hello function is defined in the global scope and as such is a property of the window object.
+12