js listen for 2 events code example
Example 1: how to add multiple event listener in javascript
function addMultipleListeners(element,events,handler,useCapture,args){
if (!(events instanceof Array)){
throw 'addMultipleListeners: '+
'please supply an array of eventstrings '+
'(like ["click","mouseover"])';
}
var handlerFn = function(e){
handler.apply(this, args && args instanceof Array ? args : []);
}
for (var i=0;i<events.length;i+=1){
element.addEventListener(events[i],handlerFn,useCapture);
}
}
function handler(e) {
};
addMultipleListeners(
document.getElementById('first'),
['touchstart','click'],
handler,
false);
Example 2: multiple event with javascript
document.getElementById("tg").onclick = function ()
{
my_fun1();
my_fun2();
}
function my_fun1()
{
var x = document.getElementsByClassName("adv")
for(var i=0; i<x.length;i++) {
if (x[i].style.display === "none") {
x[i].style.display = "block"
flag = false
} else {
x[i].style.display = "none"
flag = true
}
}
}
function my_fun2()
{
var x = document.getElementsByClassName("btnpro")
for(var i=0; i<x.length;i++) {
if(flag){
x[i].style.width = "80px";
}else{
x[i].style.width = "60px";
}
}
}