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

有帮助吗?

解决方案

You can use :visible Selector

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

DEMO

其他提示

Try with :visible selector of jQuery.

$('.myClass:visible')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top