[jQuery] Re: Adding events to newly added fields
What is the focusin/focusout approach? On Feb 8, 12:48 pm, Ariel Flesler [EMAIL PROTECTED] wrote: Indeed, Listen won't work for events that don't bubble. blur and focus can be patched with the focusin/focusout approach. I don't know anything about delegate. LiveQuery is the easiest to implement and it should work just fine. If your site is really big, as in, you have lots of bindings and you are constantly renewing them, then event delegation might be necessary. Listen and Intercept are similar, Intercept has full support for simple selectors, but it's constantly calling .is(), so it might get slow if it's actioned too often. Listen only supports a set of selectors, but it should be almost 100% scalable, as selectors are indexed. In short, if LiveQuery works fast enough for your site, it'll be the faster to use. If not, then, if the selectors Listen supports are enough for you, it should be the faster approach, else Intercept might be the one. Well.. it's up to you :) Cheers Ariel Flesler On 7 feb, 21:01, bikuta [EMAIL PROTECTED] wrote: Cool thanks, but it doesn't work for blur and change. I guess that's because they don't bubble. I saw the intercept plugin and there's also livequery. Apparently there's also a delegate plugin, but I can't find it. I'm not sure what I should use to get the best performance. Any suggestions? On Feb 8, 2:08 am, Ariel Flesler [EMAIL PROTECTED] wrote: This can help you do what Juha said:http://flesler.blogspot.com/2007/10/jquerylisten.html Cheers Ariel Flesler On Feb 7, 11:37 am, Juha Suni SC [EMAIL PROTECTED] wrote: bikuta wrote: The way I'm adding the item is just by adding another row to the html table using the append() method. Should I be doing it another way? Instead of binding the events for all the rows individually, just bind the events once to the container element. It's events get triggered as the event bubbles up the DOM, and there you can use e.target to check which element was actually clicked etc... This way you: A) Only bind events once, for one object instead of many (fast, clear) B) Don't need to bind events agains as rows are added (fast, simple). Search this group for Event delegation or Event bubbling and you should find further information. -- Suni- Ocultar texto de la cita - - Mostrar texto de la cita -
[jQuery] Re: Adding events to newly added fields
Well at the moment I'm using LiveQuery and Listen . Listen for the events that bubble and LiveQuery for the ones that don't. I'm interested in using event delegation though, because I'd like to optimize as much as possible. So if I wanted to use delegation, would the Intercept plugin be the way to go? Searching through this forum I found this: http://dev.jquery.com/browser/trunk/plugins/delegate/jquery.delegate.js However there doesn't seem to be any documentation on it. On Feb 8, 12:48 pm, Ariel Flesler [EMAIL PROTECTED] wrote: Indeed, Listen won't work for events that don't bubble. blur and focus can be patched with the focusin/focusout approach. I don't know anything about delegate. LiveQuery is the easiest to implement and it should work just fine. If your site is really big, as in, you have lots of bindings and you are constantly renewing them, then event delegation might be necessary. Listen and Intercept are similar, Intercept has full support for simple selectors, but it's constantly calling .is(), so it might get slow if it's actioned too often. Listen only supports a set of selectors, but it should be almost 100% scalable, as selectors are indexed. In short, if LiveQuery works fast enough for your site, it'll be the faster to use. If not, then, if the selectors Listen supports are enough for you, it should be the faster approach, else Intercept might be the one. Well.. it's up to you :) Cheers Ariel Flesler On 7 feb, 21:01, bikuta [EMAIL PROTECTED] wrote: Cool thanks, but it doesn't work for blur and change. I guess that's because they don't bubble. I saw the intercept plugin and there's also livequery. Apparently there's also a delegate plugin, but I can't find it. I'm not sure what I should use to get the best performance. Any suggestions? On Feb 8, 2:08 am, Ariel Flesler [EMAIL PROTECTED] wrote: This can help you do what Juha said:http://flesler.blogspot.com/2007/10/jquerylisten.html Cheers Ariel Flesler On Feb 7, 11:37 am, Juha Suni SC [EMAIL PROTECTED] wrote: bikuta wrote: The way I'm adding the item is just by adding another row to the html table using the append() method. Should I be doing it another way? Instead of binding the events for all the rows individually, just bind the events once to the container element. It's events get triggered as the event bubbles up the DOM, and there you can use e.target to check which element was actually clicked etc... This way you: A) Only bind events once, for one object instead of many (fast, clear) B) Don't need to bind events agains as rows are added (fast, simple). Search this group for Event delegation or Event bubbling and you should find further information. -- Suni- Ocultar texto de la cita - - Mostrar texto de la cita -
[jQuery] Re: Adding events to newly added fields
Cool thanks, but it doesn't work for blur and change. I guess that's because they don't bubble. I saw the intercept plugin and there's also livequery. Apparently there's also a delegate plugin, but I can't find it. I'm not sure what I should use to get the best performance. Any suggestions? On Feb 8, 2:08 am, Ariel Flesler [EMAIL PROTECTED] wrote: This can help you do what Juha said:http://flesler.blogspot.com/2007/10/jquerylisten.html Cheers Ariel Flesler On Feb 7, 11:37 am, Juha Suni SC [EMAIL PROTECTED] wrote: bikuta wrote: The way I'm adding the item is just by adding another row to the html table using the append() method. Should I be doing it another way? Instead of binding the events for all the rows individually, just bind the events once to the container element. It's events get triggered as the event bubbles up the DOM, and there you can use e.target to check which element was actually clicked etc... This way you: A) Only bind events once, for one object instead of many (fast, clear) B) Don't need to bind events agains as rows are added (fast, simple). Search this group for Event delegation or Event bubbling and you should find further information. -- Suni
[jQuery] Finding index of the first empty text field
Hi all, I'm trying to find the index of the first empty text field (class name is item). I am able to get the text field object by using: $([EMAIL PROTECTED]'']) However I can't get the index, i.e., which text field is it? The number of text fields are dynamic, but there will always be at least one that is empty. Using: $([EMAIL PROTECTED]'']).index(this); Returns: -1 Also tried $(.item).index($([EMAIL PROTECTED]''])); also returns -1 Anyone know how to do it? Cheers.
[jQuery] Adding events to newly added fields
Hi I am trying to make form which contains a list of items. I have a set of events which need to be bound to each item, at the moment everytime I add a new item, I have to unbind all items and add the event again to all items for the new item to work like the rest of them. This means my application becomes quite slow as the number of items becomes very large. Is there a better way to bind events only to newly added items? or is there something I can do to speed things up? The way I'm adding the item is just by adding another row to the html table using the append() method. Should I be doing it another way?