I'm trying to add 'selected
' to a element but the code doesn't execute at all.
Any suggestions why ?
The code is:
$.post('./question_in_test.php',
{
questionId : vars[0]
} ,
function(data) {
$("#testQuestion > option").each(function () {
console.log("Something happens"); // Doesn't execute at all
if (this.value === data) {
$(this).prop('selected', 'selected');
}
});
console.log("NUmber id : " + data + " vars[0] : " + vars[0] ); // Shows on the console
}
);
on the PHP
page, I have a select
which I have retrived from the database .
<select id = "testQuestion">
<optgroup label="Category 1">
<option>Option 1...</option>
</optgroup>
</select>
</select>