I bow, MorningZ. Many thanks and much respect - SA
On May 18, 10:47 pm, MorningZ <morni...@gmail.com> wrote: > The index of the object you are looking for needs to be in the > collection of objects you select..... which isn't the case of your > selector, as you are looking for an <option> tag in a collection > (that's just one item) of <select> tags > > Right from the docs (http://docs.jquery.com/Core/index) > > "Searches every matched element for the object and returns the index > of the element, if found, starting with zero" > > so, knowing this > > $("#mySelect option").index($("option[value=1]")) > > Should give you the value you are looking for > > On May 18, 10:07 pm, Sasha <sasha.akh...@gmail.com> wrote: > > > Seems like this should be straightforward based on the documentation: > > > ... > > <select id="mySelect"> > > <option value="0" selected="selected">whatever</option> > > <option value="1">other whatever</option> > > </select> > > ... > > <script> > > $(document).ready(function(){ > > alert($("#mySelect").index($("option[value=1]")));}); > > > </script> > > > ought to alert "1" - right? Instead I get "-1". > > > If I change "#mySelect" in the <script> block to "*", I get "16", the > > true index of the option among all the elements of the page. But I'm > > wanting to find the index of the option element within the select > > element. > > > Thanks to anyone who can help! SA