Today I learned how to listen to <select> change events, and store the selected option in plain-jane javascript:

See the Pen phLAj by Jesse Shawl (@jshawl) on CodePen.

I had never heard of the selectedIndex method, so I checked out the documentation on the mozilla developer network.

I’m not sure this is super useful outside the context of dropdown menus, but it’s a heck of a lot easier than looking for selected attributes and removing them, which can be a pain to manage.

Instead, you can just set selectNode.selectedIndex to -1, which will deselect all options.

Edit this Post