0

I'm trying to select several list elements based on a variable in the jquery selector like so:

    var testCase = jQuery.trim('li.' + $.trim(menu_type));
    $('#sidebar-wrapper').find(testCase).show();

menu_type is a variable produced earlier in the code.

it works fine on firefox/chrome/safari but not on ie8... I searched on google and here for this problem, but didn't find a solution that worked for me. :(

edit: here is more code, explaining what i'm trying to do (sorry for the little information before):

    $('select#menu_select_event').change(function(event) {
    var menu_type = "";
    var $classList = $(this).find(":selected").classList();
    for (var i = $classList.length - 1; i >= 0; i--) {
        if ($classList[i].length > 4 && $classList[i].substr(-4) === "Menu") {
            menu_type = $classList[i];
        };
    };
    var testCase = jQuery.trim('li.' + menu_type);
    $('#sidebar-wrapper').find(testCase).show();
    $('#sidebar-wrapper').find(testCase).first().find('a').trigger('click');
    $('#sidebar-wrapper').find('li').not('.' + menu_type).hide();
    if (menu_type == 'allMenu') {
        $('#menu_type_explanation').text("通常と弁当メニュー");
    } else {
        $('#menu_type_explanation').text(jpfy($.trim(menu_type)) + "メニュー");
    }

});

classList() is a jquery plugin I wrote. What I just found out: menu_type is actually empty on ie8, so I think

$(this).find(":selected")

doesn't work on IE8? Is there something else I could use that definitely works on IE8 as well?

Martin
  • 1,112
  • 1
  • 11
  • 31
  • any error? or screenshots ? what is ie8 problem ? – daremachine Mar 18 '15 at 00:39
  • @daremachine, you can see error in title. :) However, OP could provide context (more code, and html/css). Maybe this could be solved on another way... – sinisake Mar 18 '15 at 00:42
  • @Cyrus hmm... try log your testCase selector if is valid. And you dont need do first trim because it is not necessary in your case – daremachine Mar 18 '15 at 00:47
  • @Cyrus look here may be helpfull ... it seems like a jquery library. http://stackoverflow.com/questions/14347611/jquery-client-side-template-syntax-error-unrecognized-expression – daremachine Mar 18 '15 at 00:51
  • what is `menu_type`? looks like that is empty which is creating a selector like `li.` which is an invalid selector thus the error – Arun P Johny Mar 18 '15 at 00:55
  • Sorry for the little information in my initial post. I added the whole function. And console.log of menu_type works fine in Firefox, but alert(menu_type) doesn't show anything in IE8... so I guess .find(':selected') is not a valid selector in IE8? – Martin Mar 18 '15 at 04:43

0 Answers0