0

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 ?

Python
  • 169
  • 1
  • 3
  • 10
  • Are you working on a Mac, or on Windows? If you have a Mac, you should be able to connect your ipad to your laptop, and do some debugging to get a better idea of what the issue is. – KDot Oct 22 '15 at 13:47
  • i found a way to use console on the ipad by including $('#activity_filter_type_activity option').eq(1).prop("selected", true); doesnt product any result – Python Oct 22 '15 at 13:49

4 Answers4

0

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()

Community
  • 1
  • 1
RBoschini
  • 496
  • 5
  • 16
0

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.

KDot
  • 496
  • 2
  • 7
  • i tried $('#activity_filter_type_activity option').attr("selected", "selected"); too and it doesnt work :( – Python Oct 22 '15 at 16:25
0

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;
    }
0

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
}
Jonathan Marzullo
  • 6,879
  • 2
  • 40
  • 46