首页 > 解决方案 > jQuery - Remove last item of multiple selects that starts with same ID

问题描述

I have a table that has multiple rows. This table has in a column a SELECT that starts with ID=next_(rowindex)

What I need is when I button clicks the event to remove the last option of each SELECT.

I'm doing this right now but is not working because is removing the last option of the last SELECT.

$("select[id^='next_'] option").last().remove();

And what I need is that all SELECT elements have the same items, so each one gets the last item removed.

Any clue?

标签: jquery

解决方案


要删除多选的最后一个选项,请使用以下代码:

$("select[id^='next_'] option:last-child").remove();

它将选择所有 id 以“next_”开头的选择的最后一个选项子项,并将其删除。


推荐阅读