I want to remove few options, say, last three options, from a select box out of 5 options, using jquery
Below is the select box with 5 options tag
<select id="select">
<option>first</option>
<option>second</option>
<option>third</option>
<option>fourth</option>
<option>fifth</option>
</select>
UPDATE:
I tried this code
$("#select option:not(option:first, option:last)";
But that gave me uncaught exception in console
slice()
方法是解决方法:
$("#select > option").slice(-3).remove();
What have you tried? I think the nth-child selector might be what you're looking for.
您可以使用以下代码删除最新的项目http://jsfiddle.net/QxmvC/
$('#select').children().slice(-3).remove();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.