After a ajax call i populate a select option in this way adding a value attribute and another one called jobDescription:
$.each(obj, function(key, value) {
$('#mySelect').append($("<option></option>").attr({"value": value.id, "jobDescription": value.jobDescription}).text(value.name));
});
when i select one of the option i need to get the jobDescription value. To do that I tried in this way
$("#mySelect").on('change', function() {
console.log($(this).attr("jobDescription"));
});
but it returns undefined. Is there any other way to do that?
Going by your original code, you need to first add
find(':selected').first before the.attrto find the current selected<option>in#mySelect.