Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery find which one is visible

<select id="milesAway">
    <option id="5" value="5">5 miles</option>
    <option id="10" value="10">10 miles</option>
    <option id="25" value="25">25 miles</option>
    <option id="50 value="50">50 miles</option>
    <option id="100" value="100">100 miles</option>
    <option id="250" value="250">250 miles</option>
    <option id="500" value="500">500 miles</option>
</select>
<input type="text" id="zipCode" />
<input type="text" id="cityState" class="cityState" />

So at any point in time, only one of these 3 available inputs will be shown. They are all controlled by .show() and .hide()

I do I use JQuery to find out which one is the one that is shown and get it's id.

Thanks!

like image 935
Scott Avatar asked Nov 15 '22 00:11

Scott


1 Answers

you can do

$(':input:visible') //This will selects all inputs on the page. You can narrow this down by specifying an ID that wraps the input you are looking or.

You can also check if input is visible by doing

$('#cityState').is(':visible') 
like image 146
Hussein Avatar answered Dec 05 '22 12:12

Hussein