Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing all option of dropdown box in javascript

Tags:

javascript

How can i dynamically remove all options of a drop down box in javascript?

like image 619
akshay Avatar asked Jan 06 '11 19:01

akshay


People also ask

How do I remove all select options?

To remove all options from a select list using jQuery, the simplest way is to use the empty() method. If we want to remove all options from the select list, we can use the jQuery empty() method to do this with the following Javascript code.

How do you reset a drop down?

The following HTML Markup consists of an HTML DropDownList (DropDown) control and a Button. When the Button is clicked, the Reset JavaScript function is executed. Inside this function, the SelectedIndex property of the DropDownList is set to 0 (First Item).

How do you remove all options from select in jQuery except first?

Explanation: If we want to remove all items from dropdown except the first item then we can use $('#ddlItems option:not(:first)'). remove(); Here we have excluded first item from being deleted. If we want to remove all items from dropdown except the last item then we can use $('#ddlItems option:not(:last)').


1 Answers

document.getElementById('id').options.length = 0; 

or

document.getElementById('id').innerHTML = ""; 
like image 195
hunter Avatar answered Sep 19 '22 15:09

hunter