Domanda

I have a page with several HTML dropdowns.

All dropdowns have the same class and there is always only one of them visible on the page at a time (the others are hidden with jQuery based on different rules before).

How can I get only the value of the currently visible element out of this class ("myClass") ?

Example dropdown:

<select class="myClass" id="status1" name="status1">
    <option value="item1">Item 1</option>
    <option value="item2">Item 2</option>
    <option value="item3">Item 3</option>
</select>

Many thanks for any help with this, Tim

È stato utile?

Soluzione

You can use :visible Selector

$('.myClass:visible').val()

DEMO

Altri suggerimenti

Try with :visible selector of jQuery.

$('.myClass:visible')
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top