I added onclick event to my select tag like in the following code -
<option onclick="alert('Hello')">Say Hello</option>
but it does not work....
How can I set the option onclick event to fire ?
I prefer using Ids to add event listener to separate your code from html so I add an Id to your select tag with "my-select" for example and select this tag by its Id and add onchange event listener. This is the code:
<select id="my-select">
<option value="1">Say Hello</option>
</select>
<script>
document.getElementById("my-select").addEventListener("change", printMsg);
function printMsg() {
alert("Hello");
}
</script>
option. useonchangeevent inselectinstead.