preventDefault() won't work for me

后端 未结 2 741
星月不相逢
星月不相逢 2021-01-27 04:59

Why will this refuse to work?
HTML stuff


                      
相关标签:
2条回答
  • 2021-01-27 05:13

    Filter only filters what is already selected. In your case, the #nav-bar element.

    You need this:

    $('div#nav-bar a').click(function(event){
            event.preventDefault();
        });
    
    0 讨论(0)
  • 2021-01-27 05:27

    filter is the wrong method to use here. you should either use find to look for elements in a selection:

    $('div#nav-bar').find('a')...
    

    or simply combine that into one selector:

    $('div#nav-bar a')...
    

    after you've fixed that, your preventDefault will actually get applied and work, theres nothing wrong with that piece of code directly.

    0 讨论(0)
提交回复
热议问题