Counting the number of option tags in a select tag in jQuery

前端 未结 8 1808
夕颜
夕颜 2020-12-04 18:39

How do I count the number of s in a

8条回答
  •  难免孤独
    2020-12-04 19:03

    You can use either length property and length is better on performance than size.

    $('#input1 option').length;
    

    OR you can use size function like (removed in jQuery v3)

    $('#input1 option').size(); 
    

    $(document).ready(function(){
       console.log($('#input1 option').size());
       console.log($('#input1 option').length);
    });
    
    

提交回复
热议问题