Scot
Scot

Reputation: 17

setTimeout function not working in ie11

I am using the following code to simulate a click as soon as a specific page loads:

jQuery(function($){
    setTimeout(function() {
        $('ul.dk_options_inner li:nth-child(2) a').trigger('click');
    }, 200);
});

This works in all browsers apart from IE11. Are there any alternatives ways to adjust this to ensure compatibility with IE11?

Upvotes: 0

Views: 582

Answers (1)

Marcos Pérez Gude
Marcos Pérez Gude

Reputation: 22158

Better if you attach on document ready, that's the DOM is ready to use:

$(document).ready(function() {
    $('ul.dk_options_inner li:nth-child(2) a').trigger('click');
});

You don't need to make an asynchronous method (like setTimeout()) and it works in all browsers (mobile included)

Upvotes: 1

Related Questions