Pls can someone help me with code? I want to change option in select after page is loaded cuz form is generated with DOM.
I dont know why - with "onClick" is it working:
$(window).load(function() {
$( "#target" ).click(function() {
$("#filter_1 option[value=11]").attr('selected', 'selected').trigger('change');
});
});
But i want to change select without click and this is not working:
$(window).load(function() {
$("#filter_1 option[value=11]").attr('selected', 'selected').trigger('change');
});
What am i doing wrong?
Edit - i found out that all "options" are not there yet, when i'm trying to change them. Working solution is:
$(function() {
function changeOption() {
$("#filter_1 option[value=11]").attr('selected', 'selected').trigger('change');
}
setTimeout(function(){
changeOption();
}, 500);
});
Is there any better solution than Timeout?