How to remove options from select element using jQuery ?
The task is to remove the option elements from the select element using jQuery.
Approach:
- Select the option from select which needs to remove.
- Use JQuery remove() method to remove the option from the HTML document.
Example 1: This example removes the option of which val = ‘val_1’ using remove() method.
<!DOCTYPE HTML> <html> <head> <title> JQuery | Remove options from select. </title> <script src= </script> </head> <body style="text-align:center;" id="body"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 15px; font-weight: bold;"> </p> <select> <option value="val_1"> Val_1</option> <option value="val_2"> Val_2</option> <option value="val_3"> Val_3</option> <option value="val_4"> Val_4</option> </select> <br> <br> <button> click here </button> <p id="GFG_DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p> <script> $('#GFG_UP').text( 'Click on the button to '+ 'remove a option from select'); $('button').on('click', function() { $("option[value='val_1']").remove(); $('#GFG_DOWN').text( 'option with val_1 is removed!'); }); </script> </body> </html> |
chevron_right
filter_none
Output:
-
Before reaching the bottom:
-
After reaching the bottom:
Example 2: This example removes the options of which class = ‘val’ using remove() method.
<!DOCTYPE HTML> <html> <head> <title> JQuery | Remove options from select. </title> <script src= </script> </head> <body style="text-align:center;" id="body"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 15px; font-weight: bold;"> </p> <select> <option class="val" value="val_1"> Val_1 </option> <option class="val" value="val_2"> Val_2 </option> <option value="val_3"> Val_3 </option> <option value="val_4"> Val_4 </option> </select> <br> <br> <button> click here </button> <p id="GFG_DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p> <script> $('#GFG_UP').text( 'Click on the button to remove a option from select'); $('button').on('click', function() { $("option[class='val']").remove(); $('#GFG_DOWN').text( 'option with class = "val" are removed!'); }); </script> </body> </html> |
chevron_right
filter_none
Output:
-
Before reaching the bottom:
-
After reaching the bottom:
Recommended Posts:
- How to add options to a select element using jQuery?
- How to select an element by name with jQuery?
- How to remove parent element except its child element using jQuery ?
- JQuery | Remove “disabled” attribute from an element
- jQuery | select() with Examples
- How to remove items from a select box ?
- How to select ID that starts with certain character using jQuery ?
- HTML | DOM Select remove() Method
- How to set the value of a select box element using JavaScript?
- How to select all children of an element except the last child using CSS?
- How to set the default value for an HTML <select> element?
- jQuery | remove()
- jQuery | Remove Elements
- How to fadeOut and remove a div using jQuery ?
- How to Add and Remove multiple classes in jQuery ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



