开发者

jQuery: Selecting option elements by their value

I'd like to remove a specific option from some select boxes (all with the same values) if their value is "1". The problem is, I'm having difficulty filtering elements down to that specific value.

At the moment, the closest I've got is

$('.demoClass').find('option:contains(1)').remove();

but there are two problems. Firstly, this seems to iterate over the (displayed) contents of the option, not its value...and secondly, it seems to return true the contents contain that value, as opposed to being that value. (Eg contains(1) will return true for (1, 10, 11, 12)...when I 开发者_JS百科want it to return true for "1" only)

In short, what I'm looking to do is find the timeslot option with value X inside all select boxes of class ".demoClass" and remove them. Any suggestions appreciated.


Try this...

$('.demoClass').find('option[value="1"]').remove();

This utilizes the Attribute Equals Selector

jQuery: Selecting option elements by their value


Try this:

$('.demoClass').find('option[value=1]').remove();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜