Is is not just a case of replacing jQuery(document) with jQuery
(this.context) in .live() and .die() functions?
This works when the context is supplied as an element, eg:
var elem = $('#my-buttons')[0];
$(':button', elem).live('click', ...);
but not as a selector or another jQuery object:
$(':button', '#my-buttons').live('click', ...);
Although, I think this is acceptable behaviour, as you wouldn't want
to bind to the context unless you were absolutely sure it existed and
remained static.
Anyway I'm probably overlooking some bigger picture here.
- Mark
On Jan 28, 2:28 pm, John Resig <[email protected]> wrote:
> We've definitely been looking into adding this - but for now we
> wanted to keep the API simple. Will try and tackle this for 1.3.2.
>
> --John
>
> On Tue, Jan 27, 2009 at 11:47 PM, Mark Gibson <[email protected]> wrote:
>
> > Hi, I was browsing through the new jQuery code and noticed that .live()
> > always binds events to document. I was wondering whether it would be
> > more efficient to bind them on the context if present - ie. to prevent
> > events from unnecessarily bubbling all the way up to document.
>
> > so that:
>
> > $('button', container).live('click', function(ev) {
> > var button = this;
> > ...
> > ev.stopPropagation();
> > });
>
> > events are bound to 'container', and the function prevents further
> > propagation.
>
> > I know that this kind of thing can currently be done more efficiently
> > than using live like this:
>
> > $(container).bind('click', function(ev) {
> > var button = $(ev.target).closest('button');
> > ...
> > });
>
> > so wouldn't binding live on the context leverage live for more useful
> > situations like this, and take the strain off binding to document?
>
> > I've not had chance to test this out, I thought I'd raise the issue
> > for discussion first before spending too much time on the matter.
> > Maybe I've completely overlooked something ;)
>
> > Regards
> > - Mark Gibson
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---