Saturday, May 30, 2009

[jQuery] Re: question re: .live() and .empty()

Thanks guys, I understand now.

Related question (but maybe for the UI guys)... does anyone know if any jquery UI components (sortables and dialog in particular) bind events to something outside their own scope (like by using .live())? I'm guessing not and that I'm safe instantiating one of those components on a dynamically created DOM node that I can then get rid of using .empty() on it's parent and no event handlers will be left behind, but am not sure.

Thanks,
Jack

Karl Swedberg wrote:

On May 30, 2009, at 12:14 PM, Jack Killpatrick wrote:

Thanks, Brandon. So .empty() won't touch events that were bound using a selector on objects inside what is being emptied, right? Gotta use .die() to get rid of them?

Yes and no. empty() will unbind events that were bound to the elements that are being removed. But since live() is actually binding the events to document, they won't be unbound unless you you use die()  -- or maybe $(document).unbind()

Hope I didn't just muddy the waters. 

--Karl

Brandon Aaron wrote:
The .live() method binds event handlers at a higher level than the node(s) selected. So, in other words the events aren't actually bound to specific nodes so they won't be removed when you call empty.  If you need to remove a live event, just call .die(). It is like .unbind() but for .live() events. http://docs.jquery.com/Events/die#typefn  -- Brandon Aaron  On Fri, May 29, 2009 at 10:06 PM, Jack Killpatrick <jack@ihwy.com> wrote:   
I'm guessing that once a .live() instantiation occurs it's there for good. If that's the case, is there a way to destroy it? (in particular as it pertains to a selector).  I'm debating using it in a plugin, but am wary because of what could happen with multiple instances of the plugin and maybe no ability to destroy it completely.  Thanks, Jack  Jack Killpatrick wrote:     
Hi All,  Wondering if someone knows the answer to this:  Using jQuery 1.3.2, if some items inside a div have events bound to them via .live() and then .empty() is called on the div will the events that were bound via .live() get removed? The .empty() doc says:  http://docs.jquery.com/Manipulation/empty  Note that this function starting with 1.2.2 will also remove all event handlers and internally cached data.  But something I'm working on makes me think that the .live() events are not removed. I haven't nailed it down yet.  Thanks, Jack         
    
   



No comments: