Assign a function and pass parameter at the same time - Javascript Function

Javascript examples for Function:Function Argument

Description

Assign a function and pass parameter at the same time

Demo Code

ResultView the demo in separate window

<!doctype html>
<html>
   <head> 
      <title>atest</title> 
      <script>
window.onload=function(){//from ww  w. j a v a2 s  . c o  m
   var c=document.getElementsByTagName('div')[0].childNodes,
   l=c.length,
   filterByClass=function(){
      console.log(this.id);
   };
   while(l--){
      c[l].onclick=filterByClass;
   }
}

      </script> 
   </head> 
   <body> 
      <div> 
         <button id="classA">A</button> 
         <button id="classB">B</button> 
         <button id="classC">C</button> 
      </div>  
   </body>
</html>

Related Tutorials