Let\'s assume you have the following HTML5
I use select2 to load all of my options dynamically (from an array), and this is what I have been able to use successfully:
$('#element').select2('data')[0].dataAttribute;
where the id of the select is 'element', and dataAttribute is the custom attribute for the option i'm trying to retrieve.
we can simply do this like:
$(this).find(":selected").data("id")