All,
I’m removing some select options with jQuery using the following code:
$('#other_liked_vendors option[value=' + clicked_id + ']').remove();
length = $("#other_liked_vendors").val().length;
alert(length);
if($("#other_liked_vendors").val().length === 0){
$("#view_other_liked_vendors").hide();
}
I’m basically trying to say if the last select element has been removed then I’d like to hide the div that the select element is in. Can anyone show me how to check this correctly?
Thanks!
You can use the
.lengthproperty of the jQuery object to see how many elements matched. So:You were trying to use the length of the
.val(), which is the length of the string that is the currently selected option’s value…