开发者

disable jQuery's preventDefault for children

I have a menu ul (depth 2) . I want the parent links to be unclickable so I fixed this:

$('li.parent a').click(function(e) {
    e.preventDefault();
});

This also disabled clicks for the children, and I Cant seem to find the opposite function for preventDefault, like so:

$('li.parent a li a').click(function(e) {
    e.goAndEnjoyYourDefaultBehaviourYoungPadawan();
});

Does that exist, or is there another best prac开发者_运维百科tice?

Note: I cant edit the menu, or add id's to the <a>'s or sommit.


You need to use the child selector rather than the descendant:

$('li.parent > a').click(function(e) {
    e.preventDefault();
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜