Dot Net Developer Dot Net Developer - 4 months ago 17
ASP.NET (C#) Question

How to toggle javascript functions using jquery

I have two javascript functions

function A(){
alert("A() function is called");
}

function B(){
alert("B() function is called");
}

$("#button").click(function(){
// I need to toggle A() and B() here
});


How can I achieve this, can any one please help on this?

Answer

you can do by applying class to the button and write depends on class

Live Demo

 <input type="button" class="callA" value="click me" id="button" />

 $("#button").click(function(){

   if($(this).hasClass('callA')){
           A();
    }
   else
    {
          B();
    }
 });
Comments