You need to unselect the currently selected option first:
var d = $('<div />').append(data).find('option').prop('selected', true);
$("#LicenseId").find('option').removeProp('selected').end().append(d);
문제
I am dynamically adding an option to a selectList and trying to make it the selected item but the following code does not seem to make the option selected. It does ad the option, however.
$("#LicenseId").append(data).prop("selected", true);
What am I doing wrong, please?
해결책 2
You need to unselect the currently selected option first:
var d = $('<div />').append(data).find('option').prop('selected', true);
$("#LicenseId").find('option').removeProp('selected').end().append(d);
다른 팁
Aside from using prop, you could also try the attr method.
$("#LicenseId").append(data).attr("selected", "selected");