简体   繁体   中英

Dropdown change event not firing in IE

I'm having some problems with some jQuery function not working in IE11 (works ok in Chrome).

For giving some context - I have a dropdown with years which certain logic should only be applied when you had previously selected a year prior 2000 and switch to a year 2000 or later. Is there a way to make this work in both browsers (and others)?

var sel = $("#myDropdown");
sel.data("prev",sel.val());

sel.change(function(data){
     var jqThis = $(this);
     var year = jqThis.val();


     if ((jqThis.data("prev") < 2000 && year > 1999)) {
        $(".someElements").prop("style", "display:block");
        $(".otherElements").prop("style", "display:none");
        $('select#otherDropdown').val('').trigger('liszt:updated');
        calculate();
     }
    
     jqThis.data("prev",year);
}

UPDATE: I don't see any errors in the console. After some testing and adding some alerts I can see that everything is worked as expected except the update of the other dropdown which uses the chosen jquery library:

    $('select#otherDropdown').val('').trigger('liszt:updated');

Answering myself as I've found what was the problem and the solution for it.

The following instructions are not correct as style is an attribute of the element and not a property. Funny thing is that they were still working on Chrome.

    $(".someElements").prop("style", "display:block");
    $(".otherElements").prop("style", "display:none");

Replacing this by the below using the .attr made this work in different browsers.

   $(".someElements").attr("style", "display:block");
    $(".otherElements").attr("style", "display:none");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM