Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the easiest way to remove all entries from a select dropdown using jquery?

i have a dropdown and i want to clear all items from it using jquery. i see a lot of google links about removing selected item but i want to clear ALL items from a dropdown.

what is the best way of removing all items from a select dropdown list?

like image 273
leora Avatar asked May 27 '11 12:05

leora


People also ask

How do I remove all options from a dropdown?

Select the cells with the drop-down list. Click Data >Data Validation. On the Settings tab, click Clear All. Click OK.

How remove all option from select tag in jQuery?

To remove all options from a select list using jQuery, the simplest way is to use the empty() method.

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)').

Which jQuery method is used to delete selected?

The detach() method removes the selected elements, including all text and child nodes.


1 Answers

BEST way: use .empty()

$('select').empty();

DEMO

Note: Use .remove() when you want to remove the element itself, as well as everything inside it

like image 69
diEcho Avatar answered Sep 21 '22 05:09

diEcho