jQuery: link doesn't work after .toggle()

无人久伴 提交于 2019-12-06 14:10:55

I would instead use slideToggle, bound to the click event of the button that should open the menu:

$("#nav_menu-2 ul.menu #testbutton").click(function() {
  $('ul.sub-menu').slideToggle();
});

You might have to change the selectors slightly depending how your menu is constructed.

This is a known side-effect of toggle(). The documentation says:

The implementation also calls .preventDefault() on the event, so links will not be followed and buttons will not be clicked if .toggle() has been called on the element.

To work around that, you will have to bind to click instead of toggle. As Andrew says, you can use slideToggle() to obtain the same behavior from a click event.

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