As for the first part, give this a try…
var checkedIDs = $('#test').multiselect("getChecked").map(function () {
return {name: $(this).next().text().trim(), value: this.value};
}).get();
That will return an array of objects. So to get the "name" (which is really the displayed text for the option) of the first selected option, you would do checkedIDs[0].name
.
For the second part, try this…
$('#test').append($("<option></option>").attr("value", "value1").text("text1")).val('value1');
EDIT
If all you want to do is remove any non-selected options from the list (I'm not sure what your TraceInfo
function does), just use this (replace your entire "Final code" with this)
$(jqRunningJobID).children().not(':selected').remove();
$(jqRunningJobID).multiselect("refresh");