Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove a dropdown option using jQuery?

I have a dropdown menu that is populated with snacks' names. the last option of the dropdown menu is for adding new snack and it works fine using jQuery. but all I want to know is if I can remove an option from dropdown menu. My imagination is like displaying a small delete icon in front of the option text on hovering on that option and be able to delete the option by clicking on it's delete button.

like image 564
Reza Saberi Avatar asked Jan 24 '26 20:01

Reza Saberi


1 Answers

You can use remove:

$("#snackdropdown option[value='SnackName']").remove();

Where #snackdropdown is the name of your drop down list and 'SnackName' is the item you wish to remove.

like image 89
Darren Avatar answered Jan 27 '26 13:01

Darren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!