T
T
TRIG2018-12-27 17:02:45
JavaScript
TRIG, 2018-12-27 17:02:45

How to make js code work in IE 11?

I decided to put a regular image slider on the site under Magento 2.2.
In all browsers, the slider works fine, except for IE 11.
Actually, this code does not run there:

<script type="text/javascript">
  var slider = new IdealImageSlider.Slider('#slider_news');
  slider.addBulletNav();
  slider.addCaptions();
</script>
</div>

On one resource, it is advised to wrap it in a function:
$(document).ready(function() {}
But something doesn’t work, the code stops working everywhere.
Obviously the variable var slider = new IdealImageSlider.Slider('#slider_news'); will not work if you write it inside the above function.
Please help, because I'm not strong in JS.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ihor Bratukh, 2018-12-27
@BRAGA96

<script type="text/javascript">
    ;(function ($) {
        'use strict';

        $(document).on('load', function () {
            window.slider = new IdealImageSlider.Slider('#slider_news');
            window.slider.addBulletNav();
            window.slider.addCaptions();
        });

    }(jQuery));
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question