There was a brief discussion about binding to the current context rather than document, which is similar to what you are suggesting:
http://groups.google.com/group/jquery-dev/browse_thread/thread/911a50d2a0ed64b9 John, should I raise a ticket for this? On Feb 17, 9:21 am, weepy <[email protected]> wrote: > Re the following code : > > >$(".grid").bind('click', function(ev) { > > var sq = $(ev.target).closest('.sq'); > > ... > > >}); > > Would make sense to support this with live by specifying the parent > element (".grid") in this case? > > I.e. the above could be written something like this: > > $(".sq").live("click", {parent: ".grid"} function() { > ... > > }) > > This would provide an easy way of using live handlers in a performant > manner. > > On 16 Feb, 11:35, weepy <[email protected]> wrote: > > > Ah - that's neat - thanks Mark > > > On 16 Feb, 10:33, Mark Gibson <[email protected]> wrote: > > > > .live registers all handlers on document, so in this case would have > > > to filter all click events. > > > For this case you may be better off handling this at the grid level > > > and making use of .closest: > > > > $(".grid").bind('click', function(ev) { > > > var sq = $(ev.target).closest('.sq'); > > > ... > > > > }); > > > > On Feb 15, 10:10 am, weepy <[email protected]> wrote: > > > > > I recently created a grid with ~1000 squares and each set a click > > > > event handler to each. > > > > > $(".sq").bind("click", myfunc ) > > > > > Needless to say, it was extremely slow. Thankfully I could simply > > > > switch to event delegation and far better performance by simply > > > > switching to the following: > > > > > $(".sq").live("click", myfunc ) > > > > > Rock on 1.3.1 ! > > > > > So my question : - Is there any reason *not* to use live event > > > > handlers for pretty much everything ? (other than of course the events > > > > and selectors that don't work). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
