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();
});
精彩评论