Toggle Between 2 Functions - Javascript Function

Javascript examples for Function:Function Call

Description

Toggle Between 2 Functions

Demo Code

ResultView the demo in separate window


<html>
 <head> 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
 </head> //w ww .j  a v a 2 s.  c o  m
 <body> 
  <div id="edit"> 
   <a href="#">EDIT</a> 
  </div> 
  <script>
var editAdd = [editList, addList];
function editList(){
   console.log('EDIT');
}
function addList(){
   console.log('ADD');
}
$('#edit a').click(function(e){
  e.preventDefault();
  editAdd.reverse()[0]();
});

      </script>  
 </body>
</html>

Related Tutorials