Get selected option from fieldset

Cavyn VonDeylen picture Cavyn VonDeylen · Jan 28, 2013 · Viewed 7.4k times · Source

This is causing me a lot of grief, and I'm almost positive it's something stupid.

Why is this returning undefined instead of "Test"?

See JSFiddle

<fieldset class="fieldset">
    <select class="list">
        <option selected="selected">Test</option>
    </select>
</fieldset>

<script type="text/javascript">
    alert($('.fieldset').children('select.list option:selected').val());
</script>

Answer

MG_Bautista picture MG_Bautista · Jan 28, 2013

Try this...

alert($('.fieldset').children().val());

jsFiddle Example

Greetings.