开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜