Simply trigger the change
event manually:
$(function () {
// binds the change event-handler:
$("#product-select-option-1").change(function () {
var val = $(this).val();
if (val === "Red") {
$("#red_ok").css({
"display": "block"
});
$("#yellow_ok").css({
"display": "none"
});
} else if (val === "Yellow") {
$("#yellow_ok").css({
"display": "block"
});
$("#red_ok").css({
"display": "none"
});
}
// triggers the change event:
}).change();
});
The above can, however, be reduced, and simplified, to:
$(function () {
$("#product-select-option-1").change(function () {
$('div[id$="ok"]').hide();
$('#' + this.value.toLowerCase() + '_ok').show();
}).change();
});
References: