开发者

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).c开发者_运维知识库lick(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?


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(...);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜