Home › Forums › JavaScript › jQuery Click event selector not working
- This topic is empty.
-
AuthorPosts
-
July 6, 2013 at 7:13 pm #46165
georgearnall
ParticipantHi,
I am quite new to jQuery but I know my way around (ish).
I could try and explain it but it is easier to show you a [pen](http://cdpn.io/jDcGJ “pen”).
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.
My problem is that I can only get it to hide by pressing the toggle again. I have tried to apply a class to a parent of both the menu and the content elements and using selectors write click event functions but it does not seem to be working.
Thanks for any help
July 7, 2013 at 5:55 am #141768Kuzyo
ParticipantI’m new to JS/jQuery too. Here how I fix your problem, have hope it will help http://codepen.io/Kuzyo/pen/FGIKt
I little rewrited your classes for better understanding whats going on )July 7, 2013 at 6:06 am #141770georgearnall
ParticipantThank you so much, this had been driving me crazy! I had tried a few methods but every time there was some kind of problem. Thanks for you help
July 7, 2013 at 6:22 am #141502Kuzyo
ParticipantThank you, it was a good lesson for me too
July 7, 2013 at 7:16 am #141777georgearnall
ParticipantJust realised I have made a mistake in my HTML and so this is still not working.
I placed the span toggle outside of the page wrap when actually it should be inside. I have updated my [copepen](http://cdpn.io/KjtAw “codepen”). Any ideas ?
Thanks
July 7, 2013 at 3:32 pm #141811Kuzyo
ParticipantIs it very important to put span toggle to page-wrap? Why?
July 8, 2013 at 2:50 am #141867georgearnall
ParticipantIt is essential that the toggle goes inside the page wrap just because it is the only way the design would work. What I would rather focus on is why my current selector doesn’t work.. I’m no jQuery master but I don’t understand what the problem is.
July 8, 2013 at 3:01 am #141871Kuzyo
ParticipantI know where problem is, but don’t know how to fix: if you write
$(“.page-wrap).on(“click”, function() {
$(“.wrapper”).removeClass(“active”);
})it removing class .active in the same time as it added after:
$(“.nav-toggle”).on(“click”,function() {
$(“.wrapper”).toggleClass(“active”);
})because nav-toggle inside page-wrap.
Have hope it makes sense for you. Sorry for english (
July 8, 2013 at 4:53 pm #141944georgearnall
ParticipantI found out the problem. [Here is the updated code](http://codepen.io/anon/pen/HJfxE “http://codepen.io/anon/pen/HJfxE”).
Thanks for your help
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.