YsoL8
YsoL8

Reputation: 2214

Internet Explorer 8 choking on function call (JavaScript)

I have this line in a function handling click events. It works in Firefox, but not IE8 and I don't see how to create a workaround. (Jquery answers welcome!).

n.b I cannot use the this keyword as in context it will be useless.

elementsList[i].previousSibling.lastChild.addEventListener("click", (function(el){
            return function(){
                 toggle(el)
             };
       })(elementsList[i]),false); 

edit

To answer comments

elementsList is an array containing various nodes such as divs and p tags.

Upvotes: 0

Views: 178

Answers (2)

jAndy
jAndy

Reputation: 236022

jQuery:

$( elementsList[i] ).prev().last().click(function() {
    toggle( this );
});

Upvotes: 0

Quentin
Quentin

Reputation: 943568

Internet Explorer does not support addEventListener before version 9.

Use a library to iron out the differences, since you mentioned jQuery, use bind

Upvotes: 1

Related Questions