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>

Reply via email to