Question

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

Was it helpful?

Solution

You can use :visible Selector

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

DEMO

OTHER TIPS

Try with :visible selector of jQuery.

$('.myClass:visible')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top