In one HTML page, I have 2 onclick events like this :
onclick="clear_input('button1', 'hello1','world1');"
onclick="clear_input('button2','hello2','world2');"
In a JS file I have this :
function clear_input(a, b, c) {
var text = document.getElementById(b);
var button = document.getElementById(a);
…
}
It all works. Now I want to get rid of the inline JS and implement in the JS file an addEventListener that could process any one of the 2 onclick events. How do I pass the right series of arguments ?
If it's just two, it's probably not worth effort to create some generic solution. Just add each call individually.
document.getElementById('whatever1').addEventListener('click', function(){
clear_input('button1', 'hello1', 'world1');
});
document.getElementById('whatever2').addEventListener('click', function(){
clear_input('button2', 'hello2', 'world2');
});
If you need a more generic solution you'll need to explain more about the situation, like why the arguments are 'button1', 'hello1', 'world1' to start with.