Skip to content
Advertisement

AlpineJS: which x-on directive to use inside tag? @click does not seem to work on tag

I’d like to trigger an action when a specific option is selected in select tag. @click works on every other tags, but when it doesn’t seem to work on option. Is there a directive like @selected where I can trigger an action when an option is selected?

JavaScript

Advertisement

Answer

You can’t attach events to <option> tags, but you can attach a change event to the <select> tag and use the value of the selected option.

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