Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JQuery, loop multiple select lists and their 1st option?

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
0
0
GB
Hi,

I seem to be struggling grabbing all select lists first option that are within a particular fieldset ID, and altering their attrbibutes.

I have tried
Code:
        $('#filters select option:first').each(function(){
            $(this).attr('selected',true);
            });

or
Code:
            $('#filters  select option:first').attr('selected',true);

But all it does is reset the first select list not all of them.

I've tried various selector methods using the child chevron '>' , but I can't work it out.

I've thought perhaps I should get all select lists, then for each get their first option, but I don't know how to do a selector against $(this)?

Is it possible to get an array (or JQuery object) of all select lists first options and manipulate them in this way?

Thanks,
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
OK, worked it out, I was on the right track, needed to use 'selector' with ($this)...

Code:
        $('#filters select').each(function(){
            $(this).children('option:first').attr('selected',true);
            });

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top