3

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 = $("#myDropDown option[text='someText']").attr('value');
        $("#myDropDown option[value='someID']").remove();
    }
}

I've styled my code after this answer, but it won't work.

Community
  • 1
  • 1
WEFX
  • 8,298
  • 8
  • 66
  • 102

1 Answers1

6

Try this:

$("#myDropDown option").filter(function(){
    var $this = $(this);
    return $this.text() == "SomeText";
}).remove();
Chandu
  • 81,493
  • 19
  • 133
  • 134