[jQuery] multiple elements, one function

2007-03-02 Thread dan j
Apologies if this has been answered elsewhere, but I couldn't find an answer by searching. I suppose this is a newbie question. Is it possible to assign the same function to multiple elements with different id's with one call? For example, with the code below, could I assign the onchange

Re: [jQuery] multiple elements, one function

2007-03-02 Thread Chris Domigan
Dan, You can separate your selectors with a comma. Also you don't need to specify a context (eg element type) when selecting an id. Eg #time is faster that select#time. So try: $(#time, #anotherId).change(function() {}); Cheers, Chris ___ jQuery

Re: [jQuery] multiple elements, one function

2007-03-02 Thread Glen Lipka
You might want to avoid using IDs and use a class instead. Like select class=foo or use an attribute like select bindtome=true Then $(select.foo). or $(select[bindtome=true]) will bind to multiple. Additionally, you dont have to bind the actual code there, you could call a seperate function.

Re: [jQuery] multiple elements, one function

2007-03-02 Thread Jake McGraw
Actually, you may want to avoid using custom attributes (expandos), problems with this were discussed yesterday: - Err no, actually *expandos* refers to non-standard attributes that get added to DOM

Re: [jQuery] multiple elements, one function

2007-03-02 Thread dan j
Thanks to both of you - all very useful stuff! Glen Lipka wrote: You might want to avoid using IDs and use a class instead. Like select class=foo or use an attribute like select bindtome=true Then $(select.foo). or $(select[bindtome=true]) will bind to multiple. Additionally, you dont