File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes binding and unbinding and rebinding events in jQuery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "binding and unbinding and rebinding events in jQuery" Watch "binding and unbinding and rebinding events in jQuery" New topic
Author

binding and unbinding and rebinding events in jQuery

Rob Dennett
Ranch Hand

Joined: Dec 07, 2010
Posts: 81
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

Joined: Jan 10, 2002
Posts: 61769
    
  67

I've used LiveQuery to automatically know when elements go into or out of existence.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Dennett
Ranch Hand

Joined: Dec 07, 2010
Posts: 81
The previously loaded elements aren't going out of existence, they are merely hidden.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: binding and unbinding and rebinding events in jQuery