Search code examples
jqueryclassvisible

jQuery: get value of visible element out of class


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


Solution

  • You can use :visible Selector

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

    DEMO