select onchange jquery get the selected option data attribute

JavaScript
$('#country').on('change', function(){
    let id = $(this).find(':selected').data('id');
    console.log(id);
  });$(this).find(':selected').data('id')
Source

Also in JavaScript: