In my code, I empty a <select>
element and rebuild it again with available times.
However I am trying to set the <option>
to selected if it matches the previously selected time:
if(time == currenttime) {
console.log("Matched Time "+currenttime);
$("#time-start").append($("<option></option>").attr("value", time).text(time)).prop("selected","selected");
} else {
$("#time-start").append($("<option></option>").attr("value", time).text(time));
}
I get the console message Matched Time
but the .prop("selected","selected")
isn't setting the newly created option to be selected.
How can I set it to be selected?