Wednesday, October 1, 2008

[jQuery] Re: form select...

Give this a go:

$("option","#fruits").each(function() {
$(this).attr("selected", $(this).text() == 'Pineapple' );
});

-- Josh

----- Original Message -----
From: "GARIL" <rowellx@gmail.com>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Wednesday, October 01, 2008 12:38 PM
Subject: [jQuery] Re: form select...


>
> <form>
> Select your favorite fruit:
> <select id="fruits">
> <option>Apple</option>
> <option>Orange</option>
> <option>Pineapple</option>
> <option>Banana</option>
> </select>
> </form>
>
> In the form above how do I programmatically set using jQuery the
> Pineapple option as the selected default?
>

No comments: