I've a datalist something like this
<input list="browsers">
<datalist id="browsers">
<option id="op1" value="Internet Explorer">
<option id="op2" value="Firefox">
<option id="op3" value="Chrome">
<option id="op4" value="Opera">
<option id="op5" value="Safari">
</datalist>
I'm adding "option" using jquery to datalist. Now the question is how can i find which option is selected/clicked by the user in datalist. I want to get the id of option as soon as it is is selected/clicked by user?
Try this way
http://jsfiddle.net/smap06ro/45/
Try this, I got the 'data-id' value.
You can add an ID to the input field - and listen for the input event. Then you have to get the value of the input to use in the selector to get the selected option
You can check that with is(':selected')
Or to get the selected option value