An option can be removed from a select box using 2 approaches in jQuery:
Method 1: Removing the option in the box directly
The option to be removed is selected by getting the select box. The value to be removed is specified on the value selector (value=’optionValue’) on the select box. The remove() method is then used to remove this selected option.
Syntax:
$("selectBox option[value='optionValue']").remove()
Example:
<!DOCTYPE html> <html> <head> <title> Removing an item from a select box </title> </head> <body> <h1 style="color: green"> GeeksForGeeks </h1> <b>Removing an item from a select box</b> <p> Select one from the given options: <select id="select1"> <option value="free"> Free </option> <option value="basic"> Basic </option> <option value="premium"> Premium </option> </select> </p> <p>Click the button below to remove one option from the select box.</p> <button onclick="removeOption()"> Remove option </button> <script src= </script> <script type="text/javascript"> function removeOption() { /* select the option with the value of basic and remove the option*/ $("#select1 option[value='basic']").remove(); } </script> </body> </html> |
Output:
- Before clicking the button:
- After clicking the button:
Method 2: Using the find() method
The find() method can be used to find the option in the value with the value selector. This method searches through the descendants of the specified elements in the DOM and creates a new jQuery object from the matching elements.
The select box is first selected and then the find() method is applied with the value selector to find the option. The remove() method is then used to remove this selected option.
Syntax:
$('selectBox').find('[value="basic"]').remove()
Example:
<!DOCTYPE html> <html> <head> <title> Removing an item from a select box </title> </head> <body> <h1 style="color: green"> GeeksForGeeks </h1> <b> Removing an item from a select box </b> <p> Select one from the given options: <select id="select1"> <option value="free"> Free </option> <option value="basic"> Basic </option> <option value="premium"> Premium </option> </select> </p> <p> Click the button below to remove one option from the select box. </p> <button onclick="removeOption()"> Remove option </button> <script src= </script> <script type="text/javascript"> function removeOption() { /* select the option with the value of basic and remove the option*/ $('#select1').find('[value="basic"]').remove(); } </script> </body> </html> |
Output:
- Before clicking the button:
- After clicking the button:
Recommended Posts:
- How to put items underneath each other flex box in Bootstrap 4 ?
- How to get multiple selected values of select box in php?
- How to make a placeholder for a 'select' box?
- How to set the value of a select box element using JavaScript?
- Difference between alert box and confirmation box in JavaScript
- How to change Input box borders after filling the box using JavaScript ?
- HTML | DOM Select remove() Method
- How to remove options from select element using jQuery ?
- How to remove border radius from Select tag using Bootstrap ?
- Count ways to distribute m items among n people
- Minimum number of items to be delivered
- How to prevent line breaks in the list of items using CSS?
- Python | Count number of items in a dictionary value that is a list
- Use of :even and :odd pseudo-classes with list items in CSS
- How to avoid dropdown menu to close menu items on clicking inside ?
- CSS | align-items Property
- CSS | Ordering Flex Items
- How to set hamburger items on the right in bootstrap 4 ?
- How to align navbar items to the right in Bootstrap 4 ?
- How to set vertical space between the list of items using CSS ?
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.

