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

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

How do I count the number of s in a

8条回答
  •  执念已碎
    2020-12-04 19:11

    Ok, i had a few problems because i was inside a

    $('.my-dropdown').live('click', function(){  
    });
    

    I had multiples inside my page that's why i used a class.

    My drop down was filled automatically by a ajax request when i clicked it, so i only had the element $(this)

    so...

    I had to do:

    $('.my-dropdown').live('click', function(){
      total_tems = $(this).find('option').length;
    });
    

提交回复
热议问题