I have a problem with this code :
$('#activity_filter_type_activity option').eq(1).prop("selected", true);
It works on classic desktop but not in safari/chrome on an ipad. Can you help me ?
I have a problem with this code :
$('#activity_filter_type_activity option').eq(1).prop("selected", true);
It works on classic desktop but not in safari/chrome on an ipad. Can you help me ?
try using ".attr" to checked this
$('#activity_filter_type_activity option').eq(1).attr('checked',true);
i found this solution in other thread, is the same problem .prop() vs .attr()
I think you need to use:
$('#activity_filter_type_activity option').attr("selected", "selected");
This is slightly different than the other answers.
$(element).attr("checked") is used for checkboxes, and you are trying to select an "option" input.
If you are still searching for solution... the best way is to use js not jquery. In my project i have something like this and it works perfectly
checkboxTmp = document.getElementById($(this).data('check'));
if (checkboxTmp.checked) {
$(this).children('span').css('background-position', '0px 2px');
checkboxTmp.checked = false;
} else {
$(this).children('span').css('background-position', '0px -22px');
checkboxTmp.checked = true;
}
This is how I get around attr()
or prop()
failing in Safari and or Chrome. Just check the length
of the jQuery object and selector, if :selected
if($('#activity_filter_type_activity option:selected').eq(1).length > 0){
// is selected
} else {
// not selected
}