开发者

check if option in a select dropdown is available

this might be related to this question

I have a dropdown menu that outputs a option list. In some cases the backend script outputs no options for the select tag.

I want to run a js/jquery that checks for the existence of option tags. If option tag available do nothing If no option tag available开发者_C百科 run function X.

Cheers


if ( $("#select_id option").length == 0 ) {
    function()
}


You can use length to count the number of elements matched by a selector. In this case, write a selector that matches any of the <option> tags inside your select:

if ($('select.my_select option').length > 0) {
  // There are options inside <select class="my_select">
}


$("select").each(function(){
    if(this.childNodes.length > 0)
        process();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜