开发者

Using jquery, how do I remove an item from dropdown based ONLY on its text?

开发者 https://www.devze.com 2023-03-21 13:33 出处:网络
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

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();
0

精彩评论

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