简体   繁体   English

jQuery单击选择器不起作用

[英]jQuery Click Selector Not Working

I am quite new to jQuery but I know my way around (ish). 我对jQuery很陌生,但是我知道我的解决方法。

I could try and explain it but it is easier to show you a demo ( http://codepen.io/georgearnall/pen/KjtAw ). 我可以尝试解释一下,但是向您展示一个演示更容易( http://codepen.io/georgearnall/pen/KjtAw )。

I want it so that when a user clicks on the mobile navigation toggle the menu should slide in from the side. 我想要它,以便当用户单击移动导航切换时,菜单应从侧面滑入。 Then if the user wants to close the navigation they can just tap anywhere on the page content (.page-wrap) and it will slide away again. 然后,如果用户想要关闭导航,他们可以点击页面内容上的任意位置(.page-wrap),它将再次滑开。

My problem is that the classes added during the code do not seem to work in the javascript. 我的问题是在代码中添加的类似乎无法在javascript中工作。

Also, if there is another more simple way of doing this feel free to share :) 另外,如果有另一种更简单的方法可以共享,则:)

Thanks for any help 谢谢你的帮助

Event delegation my friend. 活动委托我的朋友。 Your binding click events to classes that get added dynamically, try changing your click handlers to the following syntax: 将单击事件绑定到动态添加的类,请尝试将单击处理程序更改为以下语法:

$(document).on("click", ".active .page-wrap", function() {

Here's a demo: http://codepen.io/anon/pen/HJfxE 这是一个演示: http : //codepen.io/anon/pen/HJfxE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM