Search code examples
javascriptjqueryjquery-eventsjquery-1.3

jQuery event handlers not firing in IE


I have a list of items on a page with a set of controls to MoveUp, MoveDown and Delete.

The controls sit at the top of list hidden by default. As you mouseover an item row, I select the controls with jquery

//doc ready function:
..
var tools = $('#tools');
$('#moveup').click(MoveUp);
$('#movedn').click(MoveDn);
$('#delete').click(Delete);
..
$('li.item').mouseover(function(){
    $(this).prepend(tools);
});

This works great in Firefox .. the tools move into the current row, and the click events call the ajax functions. However, in IE6 and IE7 .. no click occurs. I tried unbinding on mouseout and rebinding on each mouseover .. to no avail.

I also looked into various reasons outside of javascript (e.g. transparent png conflicts, z-index, position:absolute) .. also no solution found.

I eventually needed to add a tools row to each item and show/hide on mouse over/out. Works just as well -- the only downer is that I have much more 'tools' markup on my page.

Does anyone know why IE ignores/drops/kills the mouse events once the objects are moved (using prepend)? And why rebinding the event afterwards also has no effect? Kept me annoyed for almost 2 hours before I gave up.


Solution

  • IE will lose events depending on how you are adding things to the DOM.

    var ele = $("#itemtocopy");
    
    $("#someotheritem").append( ele ); // Will not work and will lose events
    
    $("#someotheritem").append( ele.clone(true) );
    

    I would also recommend using .live() on the click events to simplify your code a little. Mouseover/out is not supported by live yet. http://docs.jquery.com/Events/live