سؤال

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