artworkad シ artworkad シ - 2 years ago 104
jQuery Question

Click on option event

how do I handle events for option elements?

<option value='option1'>Gateway 1</option>
<option value='option2'>Gateway 2</option>
<option value='option3'>Gateway 3</option>

When an option element is clicked I want to display a little description for the element. Any ideas how to do that?

Answer Source

You're going to want to use jQuery's change event. I am displaying the text of your option as an alert, but you can display whatever you want based on your needs. (You can also, obviously, put it inside another part of the doesn't need to be an alert.)

$('#myOptions').change(function() {
    var val = $("#myOptions option:selected").text();

Also, note, that I added an ID to your select tag so that you can more easily handle events to it (I called it myOptions).


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download