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  or use an attribute like  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.
> Lastly, you could use the 'each" if the code you want to bind is different
> depending on circumstances.
> 
> "Each" allows you to bind the code one at a time and make adjustments.
> 
> Check www.jquery.com/api for cut/paste examples.  Hope this helps.
> 
> Glen
> 
> 
> On 3/2/07, dan j <[EMAIL PROTECTED]> wrote:
>>
>>
>> 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 handler to
>> another element with a different id?
>>
>> $(document).ready(function() {
>>   // apply onchange handler to 'time' field
>>   $("select#time").change(function(){
>> // send request with amount & date as variables
>> $.post("guestCheck.php", {time: $(this).val(), date:
>> $("select#date").val()}, function(xml) {
>> //assign callback XML to JavaScript variable
>> var guests = $("guests",xml).text();
>> alert (guests);
>>});
>>   });
>>
>> Thanks for any advice.
>> --
>> View this message in context:
>> http://www.nabble.com/multiple-elements%2C-one-function-tf3332805.html#a9267242
>> Sent from the JQuery mailing list archive at Nabble.com.
>>
>>
>> ___
>> jQuery mailing list
>> discuss@jquery.com
>> http://jquery.com/discuss/
>>
> 
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/multiple-elements%2C-one-function-tf3332805.html#a9272622
Sent from the JQuery mailing list archive at Nabble.com.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


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 elements. They "expand" the attributes that are
available on an element.

For instance adding an "*expando*" attribute called "hello":

   

Because they're "non-standard" they can cause memory leak problems
under Internet Explorer if they refer to other DOM elements.

More info here:

   http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/*
expando*.asp

Karl Rudd
---

- jake


On 3/2/07, Glen Lipka <[EMAIL PROTECTED]> wrote:


You might want to avoid using IDs and use a class instead.
Like  or use an attribute like 
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.
Lastly, you could use the 'each" if the code you want to bind is different
depending on circumstances.

"Each" allows you to bind the code one at a time and make adjustments.

Check www.jquery.com/api for cut/paste examples.  Hope this helps.

Glen


On 3/2/07, dan j <[EMAIL PROTECTED]> wrote:
>
>
> 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 handler to
>
> another element with a different id?
>
> $(document).ready(function() {
>   // apply onchange handler to 'time' field
>   $("select#time").change(function(){
> // send request with amount & date as variables
> $.post("guestCheck.php", {time: $(this).val(), date:
> $("select#date").val()}, function(xml) {
> //assign callback XML to JavaScript variable
> var guests = $("guests",xml).text();
> alert (guests);
>});
>   });
>
> Thanks for any advice.
> --
> View this message in context: 
http://www.nabble.com/multiple-elements%2C-one-function-tf3332805.html#a9267242
>
> Sent from the JQuery mailing list archive at Nabble.com.
>
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


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  or use an attribute like 
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.
Lastly, you could use the 'each" if the code you want to bind is different
depending on circumstances.

"Each" allows you to bind the code one at a time and make adjustments.

Check www.jquery.com/api for cut/paste examples.  Hope this helps.

Glen


On 3/2/07, dan j <[EMAIL PROTECTED]> wrote:



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 handler to
another element with a different id?

$(document).ready(function() {
  // apply onchange handler to 'time' field
  $("select#time").change(function(){
// send request with amount & date as variables
$.post("guestCheck.php", {time: $(this).val(), date:
$("select#date").val()}, function(xml) {
//assign callback XML to JavaScript variable
var guests = $("guests",xml).text();
alert (guests);
   });
  });

Thanks for any advice.
--
View this message in context:
http://www.nabble.com/multiple-elements%2C-one-function-tf3332805.html#a9267242
Sent from the JQuery mailing list archive at Nabble.com.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


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 mailing list
discuss@jquery.com
http://jquery.com/discuss/