I'm in the process of developing a customizable button bar where I need to attach onclick event listeners to each button dynamically. The functions to be assigned should have names provided by the button's data-function attribute.
…
<div class="button-set">
<span class="function-button" data-function="func1"></span>
<span class="function-button" data-function="func2"></span>
</div>
…
Here's the script:
window.onload = function (){
var btns = document.getElementsByClassName("function-button");
for (var i=0; i < btns.length; i++) {
var b = btns[i];
b.addEventListener("click", ?????, false);
}
}
function func1() { … }
function func2() { … }
What should be added in the placeholder "????" so that the correct functions are assigned to the onclick event for each button?
I prefer achieving this without using jQuery.