abrahamgarcia27 Posted May 28, 2014 Share Posted May 28, 2014 I have a click handler that is causing some problem. I am using hammer.js for a slider. This is the link http://ingrub.com/iphone/ When you hit the last slide the text of next changes to let's grub, but the problem is that if you swipe back to an earlier screen and you try to go next it automatically goes to the link instead of going to the next slide these are some of the functions that i am using this.showPane = function(index, animate) { // between the bounds index = Math.max(0, Math.min(index, pane_count-1)); current_pane = index; var offset = -((100/pane_count)*current_pane); setContainerOffset(offset, animate); if(current_pane == 2){ $(".next2").text("Let's Grub"); $(".navigation2").addClass('linkMe'); } else { $(".next2").text("Next"); $(".navigation2").removeClass('linkMe'); } }; $( ".next2" ).click(function() { carousel.next(); $('.linkMe').click(function() { window.location = "discover.html"; }); return false; }); I am not sure what to do to fix this bug. Quote Link to comment https://forums.phpfreaks.com/topic/288829-jquery-click-handler-problem/ Share on other sites More sharing options...
kicken Posted May 28, 2014 Share Posted May 28, 2014 Removing the linkMe class will not remove the click handler you install on the element. What you should do is install the click handler on the element regardless of whether the linkMe class is present or not, but then have the handler only do something if the class is present: //Add a click handler to the navigation2 element $('.navigation2').click(function(e){ //If the element also has the linkMe class if ($(e.currentTarget).is('.linkMe')){ //Do the redirect window.location.href = 'discover.html'; } }); Quote Link to comment https://forums.phpfreaks.com/topic/288829-jquery-click-handler-problem/#findComment-1481205 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.