The toggle event cannot be delegated using jquery but we can do similar using the click event and some flags.

 


var counter = 0;
jQuery('body').delegate('#toggle-button','click',function(e){
     e.preventDefault();
     if(++counter%2){
        alert('on');
     }else{
         alert('off');
     }
  });     

The code is self explanatory. The counter is incremented on each click event and checked if it is even or odd, according to it alternately On or Off is alerted.

Comments

comments

Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.