jQuery select list removes all options

旧时模样 提交于 2019-12-02 21:54:53

this would do:

$('#selectId').html('');

Just $("#selectId option").remove(); works too.

John Forbes

$("#selectId").empty(); works for me.

The $("#selectId option").remove(); removed the select from the DOM.

Currently using jQuery JavaScript Library v1.7.1

DR.

The fastest way to accomplish this:

$("#selectId").empty();

Here are some tests: http://jsperf.com/find-remove-vs-empty

I take no credit for these tests. See this stack overflow question: How do you remove all the options of a select box and then add one option and select it with jQuery?

If without jquery:

javascript SELECT remove()

$("#selectId").options.length = 0;

That won't actually work as written because it's using a jQuery selector. It'd work if you used a straight DOM getElementById on the select list, though. Either AKX's or d.'s responses will set you right.

Try This for Multiple Select Drop Down.

$('#FeatureId').multiselect("deselectAll", false).multiselect("refresh");

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!