It is very simple to do this action, I will explain briefly how the events related to mouse, ex:click or change.
Whenever using a Jquery event the framework itself puts in the callback Function(Event) an object with all the methods and parameters you can work with. An object that you can use is the so-called timestamp, it returns you how long the event took, when you click on an object on the screen the framework takes time to identify the object data, but once loaded, when your combobox is open, click takes 0 seconds because Jquery has read the data before.
I don’t know if you got it right but once it’s loaded, just check if the timestamp is 0, then you can get the data clicked. See the example working below.
$(function() {
$('#dados').click(function(event) {
if (event.timeStamp == 0) {
var dados = $(this).val();
alert(dados);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="dados">
<option value="1">One</option>
<option value="2">Two</option>
</select>
I hope I’ve helped.
In the first example, when changing option, the two events are triggered, showing the alert twice.
– Jorge.M
Truth @Jorgematheus, better put the action to be taken on srcript itself without having to fire another event. I changed the answer.
– Laércio Lopes
Now it’s OK! + 1
– Jorge.M