Alex Sleiborg
Alex Sleiborg

Reputation: 583

JQuery children element set event

Im trying to create an event for each (a) element in a list (ul). But im doing something wrong

function EnableAjaxOnMenu(ElementID, TagName) {

    var elm = jQuery("#" + ElementID).children(TagName).click(function () {

        GetPageByUrl(jQuery(this).attr("href"));
        //ChangeSelectedMenuItem(this);
        return false;
    });

}

Does anyone know what im doing wrong here, as far as I can see it won't even create an event?

Upvotes: 0

Views: 735

Answers (1)

Nick Craver
Nick Craver

Reputation: 630359

If you're passing the <ul> ID, then you'll need .find() instead of .children() to find the <a> elements within, since they're not direct children, like this:

jQuery("#" + ElementID).find(TagName).click(...);

Or, like this:

jQuery("#" + ElementID + " " + TagName).click(...);

Upvotes: 2

Related Questions