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();
});
精彩评论