views:

27

answers:

1

I have multiple dl elements on a page. At the end of each one I have a dd tag acting as a dropdown which includes options for the element (like edit, delete, etc.)

Here's the jQuery for the dropdown:

$('dd.optiuni').mouseover(function() {
    $(this).find('ul').show();
});

$('dd.optiuni').mouseout(function() {
    $('dd.optiuni ul').hide();
});

Now before the dl tags I have an input and a submit button to add new dls and use jQuery to add them without reloading the page. The problem is that after the new element is added, the dd at the end doesn't seem to work.

How can I make my previous code recognize that new elements have been added to the page?

$(function() { // ie7 z-index fix
    var zIndexNumber = 1000;
    $('dl').each(function() {
        $(this).css('zIndex', zIndexNumber);
        zIndexNumber -= 10;
    });
});
+2  A: 

Use .live or .delegate:

$('dd.optiuni').live("mouseover", function() {
    $(this).find('ul').show();
});

$('dd.optiuni').live("mouseout", function() {
    $('dd.optiuni ul').hide();
});
karim79
Thanks Karim, this worked, but I also have a script above that's giving me the same problem. It seems to mess up the z-index on new elements only.
Norbert
Nevermind. I gave it a name and called it at the end of the addition. It works. Thanks!
Norbert