• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

binding and unbinding and rebinding events in jQuery

 
Rob Dennett
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting to build a form where sections of it are divs dynamically loaded via AJAX when needed. That is, when the page is loaded, the first div is loaded and displayed, and when next is clicked the first div is hidden and the next div is loaded and displayed. Within these divs are elements that I want to bind to some custom events when they are visible and unbind them when they are not. Since the elements are not in the DOM during the initial page load, I am using .live() to bind them and .die() to unbind them.

There is also a back button which I want to hide the current div, unbind any responders in it, show the previous div and rebind the responders in that div. The problem is that .die() seems to be a one shot deal and it seems like I can't rebind my events to the desired elements. Can someone please advise me on what should work here?

Thanks,
Rob
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've used LiveQuery to automatically know when elements go into or out of existence.
 
Rob Dennett
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The previously loaded elements aren't going out of existence, they are merely hidden.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah... hmmm. In that case I'd probably make use of custom events to trigger the hiding and unhiding. That way all the activities associated with visibility events can be consolidated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic