Let\'s assume you have the following HTML5
AA
so simple, using jquery api [tested against select2 4.x version]
$('#select').on('select2:select', function (e) { let id = $(e.params.data.element).data('id'); });