JQUERY EVENT FUNCTION TRIGGER ONCE DESPITE OF MULTIPLE TIME ATTACH

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
JQuery 
 1605  View(s)
Ratings:
Rate this:
Hi Expert!

How can i do this

html

   <button id="onclickpopupmenu">Test</button>
   <button id="popupmenuok"></button>
javascript:

$("#onclickpopupmenu").bind("click",function(){

  alert("this can execute multiple times")
  $("#popmenuok").bind("click",function(){
    alert("this has to be triggered only once eventhough the parent event trigger multiple times")
  })
})

Please help me...

Thanks in advance! 

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Jquery event function trigger once despite of multiple time attach

    Hi Jeet!

    Only bind the handler once:

    var popupmenuBound = false;

    $("#onclickpopupmenu").bind("click",function(){
      alert("this can execute multiple times");
      if (!popupmenuBound) {
        $("#popupmenuok").bind("click",function(){
          alert("this has to be triggered only once eventhough the parent event trigger multiple times");
        });
        popupmenuBound = true;
      }
    });

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!