Rob, The function $.each is *the* jQuery function - $ refers to the global jQuery object, which has a member function each(), hence that is how I refer to it. You wouldn't need to use the $ if a jQuery object was assigned to something else, e.g.
var elements = $("..."); elements.each(function() {...});
If you only need to use the element which matches that value requirement then you can include that attribute in the selector instead of iterating over the set: function test(value)
{ $("#smsUserPrice [EMAIL PROTECTED]"+value+"]").attr("selected", true); }
So you then just need to pass the value of the option to select into the function. --rob On 5/24/07, RobG <[EMAIL PROTECTED]> wrote:
On May 25, 1:29 am, "Rob Desbois" <[EMAIL PROTECTED]> wrote: > Oh yes, sorry I forgot the ); after the function passed to $.each(). > Corrected (and tested!) version is below: It seems to me that the only jQuery function necessary is .each, subsequent use of $ is unnecessary. If the intention is to select only one option (i.e. it is a single select) then the function should exit once that occurs - the following is a shorter version. I'm new to jQuery, can you show me how to get out of the loop once the correct option is found? function test() { $("#smsUserPrice option").each(function() { if ( this.value == "z" ) { this.selected = true; // stop .each loop here... how? } } } -- Rob
-- Rob Desbois Eml: [EMAIL PROTECTED] Tel: 01452 760631 Mob: 07946 705987 "There's a whale there's a whale there's a whale fish" he cried, and the whale was in full view. ...Then ooh welcome. Ahhh. Ooh mug welcome.