Change $("#DropDownList1 options") to
$("#DropDownList1 option") - Richard On Tue, Aug 11, 2009 at 11:43 PM, Ming <mcpm...@gmail.com> wrote: > > I have a DropDownList (id: DropDownList1), > i want to get the items length by Jquery, but it not work, always > return 0. > > My temporary solution is using classic javascript to do it, below is > the code. > > > <script type="text/javascript"> > $(document).ready(function() { > //method 1: > var items = $("#DropDownList1 options"); > alert(items.length); //Output: 0 = wrong > > //method 2: > alert($("#DropDownList1 options").length); //Output:0 = wrong > > //method 3: > alert(document.getElementById > ('DropDownList1').options.length); //Output: 7 = Correct! > }); > </script> >