jQuery – IE triggers several click events

Strange problem occurred today, one of the very rare occasions were the behaviour of jQuery differed between Internet Explorer and Firefox. I’ve been trying to create a minimal example that replicates the behaviour, but have failed so far.

The problem was that in IE a click event triggered several times, which led an element to be expanded and then contracted again. This did not happen in Firefox. I found out that the problem was that I had placed my jQuery segment further inside the loop than I meant to, leading to code being duplicated four or five times through the page. After removing the duplicated function names and binds to .click(), everything worked as it should.

If you get several events triggered in Internet Explorer, but not in Firefox, check that you’re not accidentally binding the same function several times (.. while creating a minimized example that does this, I got the expected behaviour in both browsers, so I’m not completely sure of the reason). It might be worth a try as a fix, tho.

One thought on “jQuery – IE triggers several click events”

  1. Just a wild guess here Mats, but could it be that this is possibly related to the document.getElementById() bug in IE(6 afaik)?

    If you have two elements, say two input fields, one with name=’foo’ and one with id=’foo’, IE will return whatever it encounters first (so basically document.getElementById will get elements by name as well).

    Not exactly sure how that can be tied to your experience, but thought it could be of some help, anyway.

Leave a Reply

Your email address will not be published. Required fields are marked *