Skip to content
Advertisement

How to get the changed select button among many select buttons?

I have many filter button like below, how can I get the select value without using its id?

JavaScript

Normally, I will use this code to find the changed select button:

JavaScript

But the problem is when there are many filter buttons, I have to write many functions like above and just only change the id.

How can I just use something like this:

JavaScript

Advertisement

Answer

Using vanilla JavaScript and the eventTarget, this is relatively straight forward. Here is an example:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement