preventDefault() won't work for me

做~自己de王妃 提交于 2019-12-02 05:48:10

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();
    });
oezi

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!