i am trying to add event to element through an function like as follow
function addevent(elements,event_n,function_n,param_trs)
{
var i = elements.length;
while (i--){
function_name=function_n+"(this.getAttribute('"+param_trs+"'))";
//function_name=function_n ;
elements[i].addEventListener(event_n,function_name);
// console.log(function_name);
}
}
this is giving error :
TypeError: Value not an object.
at elements[i].addEventListener(event_n,function_name);
so i can coll them as follow
addevent(document.querySelectorAll('tr'),'click','view_details','request_id');
to add click event to all tr example :
<tr request_id="5" onclick="view_details(this.getAttribute('request_id'))" >
or
<tr request_id="5" onclick="view_details(this)" >
how can i do it through function like above