• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

binding and unbinding and rebinding events in jQuery

 
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
 
Sheriff
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Sheriff
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic