Selecting the value of the select element, via jquery

I know how to get the value of the selected element.
The problem is with which event to catch the selection of the element. If you use click(), the first element is selected. If you use change(), then on the contrary, the first element can not be selected in any way.
Are there any other options?

Author: Vadim Ovchinnikov, 2013-10-10

3 answers

Something like that:

$("select").change(function(){
    if($(this).val() == 0) return false;
    
    alert($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<select>
    <option value="0">--Вы берите элемент--</option>
    <option value="1">Первый</option>
    <option value="2">Второй</option>
</select>
http://jsfiddle.net/Y5LsD/2/
 3
Author: mountpoint, 2017-04-09 11:17:38

If the user selects the same item in the list that was selected, then the change event does not occur, since nothing has changed. To always respond to the selection of an item, you can use the following:

$('select option:selected').click(function(){
  var value = $(this).val() || $(this).text();
  console.log(value);
});
 1
Author: Lucky, 2013-10-10 19:31:26
$('#select').on({
 'click': function(){
   console.log($(this).val());
 },
 'keyup': function(){
   if(event.keyCode==13)
    console.log($(this).val());
 },
}, 'option')
 0
Author: Антон, 2017-04-09 08:13:01