0

For the purposes of this post, please see my JSFiddle located at http://jsfiddle.net/ca7ws/

This is my menu. Clicking one of the last 3 (Scoring / Historical / Administrative) bring up a sub menu. Clicking a link on the sub menu should add the "selectedMenu" class. It appears as though it does not.

By adding alert("someText") to each function, I noticed that when

JQuery(".menuLinksSub li").click(function(){ 

is called,

jQuery(".menuCategory").click(function(){ 

is also called.

So the class is added and then immediately taken away, giving the appearance of not having worked at all.

My initial thought was that it was inherent in the NAV and UL behavior, so I even went so far as to remove all NAV / UL / LI tags in my HTML and replace them with DIV / SPAN but to no avail. The behavior is the same.

I've tried quite a bit and am stumped. Any help you may have would be greatly appreciated.

Thanks, Shadraq

4

1 回答 1

4

与大多数事件一样,该事件在 DOM 中向上冒泡。您必须从内部事件处理程序中停止它:

jQuery(".menuLinksSub li").click(function(e){
    e.stopPropagation();
    // ... your logic
}); 

http://jsfiddle.net/ca7ws/1/

于 2013-07-25T21:23:16.597 回答