How to clear all options in a dropdown box? Last Updated : 21 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Clearing the entire dropdown list is pretty easy, all we have to do is to create a button, which calls a function that performs the deletion. Let's look at the syntax of the deletion part: document.getElementById("idofdropdownlist").innerHTML = "";Here, it gets all the elements present in the given Id and clears then by assigning all the objects null, if not assigned to null, still object remains. Approach 1: Check out the code: javascript <!DOCTYPE html> <html> <body> <p>Which character is your favorite guardian?</p> <select id="guardian"> <!--dropdown list with id=guardian--> <option>Guardians</option> <option>Quill</option> <option>Gamora</option> <option>Drax</option> <option>rocket</option> <option>groot</option> <option>mantis</option> </select> <input type="button" onclick="myFunction()" value="Only IronMan clear them all" /> <!––Button which avokes myFuction()--> <script> function myFunction() { //clears all the guardians with the specified id document.getElementById("guardian").innerHTML = null; } </script> </body> </html> Output:Output1Output2Approach 2: This process not only removes the option but also removes the dropdown box too. Check out the code: javascript <html> <body> <p>Which character is your favorite guardian?</p> <select id="guardian"> <!--dropdown list with id=guardian--> <option>Guardians</option> <option>Quill</option> <option>Gamora</option> <option>Drax</option> <option>rocket</option> <option>groot</option> <option>mantis</option> </select> <input type="button" onclick="myFunction()" value="Only IronMan clear them all"> <!––Button which avokes myFuction()--> <script> function myFunction() { //process the options in a loop and removes them document.querySelectorAll( '#guardian').forEach(guardian => guardian.remove()) //here, guardian inside the for is a variable not id. } </script> </body> </html> Output:Output1output2These methods work on all browsers. Comment More infoAdvertise with us Next Article How to get selected option from Dropdown in jQuery ? T Tejashwi5 Follow Improve Article Tags : JavaScript Web Technologies Similar Reads JavaScript - How to Create Dropdown List? The dropdown list is a toggleable menu that allows to user to choose one option from multiple. The dropdown list is basically a button, when the user clicks on that, it expands downward and shows its sub-elements, from which users can select any one of them according to their preferences.Creating Dr 3 min read How to Clear Previous Appended Data onChange the Dropdown Menu? To clear previously appended data when the drop-down menu changes, jQuery is used. If the appended data is not cleared upon changing or toggling the drop-down, it will accumulate with the current menu item data. To prevent this issue, methods such as add(), remove(), addClass(), and removeClass() ar 3 min read How to get selected option from Dropdown in jQuery ? In this article, we learn how to get the selected option from the dropdown list. This article requires some familiarity with HTML, CSS, JavaScript, and jQuery. We can solve this challenge by using the jQuery val() method. The val() method in jQuery is used to set or return the value of an attribute 2 min read How to define an option in a drop-down list in HTML5 ? In this article, we will learn how to define an option in a drop-down list in HTML5. The <select> element is used to create a drop-down lists in HTML. This is generally used to present a list of options to the user in a form so that the user could choose one option as the needed one. The <o 2 min read How to select/deselect multiple options in dropdown using jQuery ? To select and deselect multiple options in a drop-down menu, we will use the HTML and CSS codes. HTML code helps to define the basic structure of the webpage and CSS will benefit in designing the web page. Some essential properties used in the code are as follows- <div> - This is a division ta 4 min read How to Edit, Copy and Delete Drop Down List in Excel Excel is a versatile tool used globally for various data management tasks, including the use of drop-down lists to simplify data entry and ensure consistency. However, there might be times when you need to modify these lists to keep up with changes in data or requirements. These essential techniques 11 min read Like