0

So I'm running a function when someone clicks on an element with a certain class name (10 of these classes). Then within that function I have another click listener for elements with another class name (another 10). I want this second click function to only occur once after that first click.

So ideally someone would click something from a set of 10, I'd then pull data from that and apply it when someone clicks an element from another set of 10. And then in order to click that second set of 10 they will have to click something from the first set again.

I'm having trouble pulling that off and I've tried some sort of .one implementation.

 $('.words_col .wrap').click(function(){
   theFunction(this)
 })

Then

 function theFunction(e) {
   $('.examples_col .wrap').click(function(){
     //allow only once.
   })
 }
2
  • Why do you need to ensure this on the code level? Couldn't you just disable the elements that are not currently clickable? Commented Dec 3, 2012 at 21:43
  • Use one() api.jquery.com/one Commented Dec 3, 2012 at 21:43

2 Answers 2

1
$('.words_col .wrap').click(function(){
   theFunction(this);
 });

function theFunction(e) {
   var oncer = true;
   $('.examples_col .wrap').click(function(){
     if(!oncer){return false;}
     oncer = false;
     //allow only once.
   })
 }

I add this as an alternative to .one because you have more than one element being selected, and .one will allow one click on each, instead of one click total.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I tried several variations of this but must've been just off. This worked great. I'd vote up but I don't have enough reputation.
0

one() will attach the click only once:

$('.words_col .wrap').on('click', function(){
   $('.examples_col .wrap').one('click', function(){
       //works only once
   });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.