Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Remove Option Elements From A Select Element Using JavaScript

DZone's Guide to

Remove Option Elements From A Select Element Using JavaScript

·
Free Resource
Pretty simple, but here it is anyway.


// The DOM way.
var sel = document.getElementById('id_of_select');
for (i = sel.length - 1; i >= 0; i--) {
	sel.remove(i);
}

// The following code removes all options from a select element, but it only works 
// in Firefox, IE and Opera. It does not work in Chrome or Safari.
sel.length = 0;


Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}