Home > DeveloperSection > Forums > Jquery event function trigger once despite of multiple time attach
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    May-02-2013 3:33 AM

 JQuery JQuery 
Ratings:


 1 Reply(s)
 1272  View(s)
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! 



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-02-2013 8:23 AM

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;
  }
});

Don't want to miss updates? Please click the below button!

Follow MindStick