When someCondition is true, I'm trying to remove a dropdown option that has "someText" as its Text. I do not know its value. It seems like this should work, but it does not. When debugging, I see that someID is undefined. Does anyone know if I've made some small syntax error?
function toggleSomeOption() {
if (someCondition() == "Foo") {
var someID = $("#myDropD开发者_运维技巧own option[text='someText']").attr('value');
$("#myDropDown option[value='someID']").remove();
}
}
I've styled my code after this answer, but it won't work.
Try this:
$("#myDropDown option").filter(function(){
var $this = $(this);
return $this.text() == "SomeText";
}).remove();
精彩评论