Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
on body click run one function after another click run another function

Is it possible to Call one function after click on body then call different function after the second click?

i tried and then stopped, any ideas?

$("html, body").one("click",function() {
  // to something
}
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You could try something like this:

var clicks = 0;
$("html, body").on("click",function() {
    if(clicks === 0){
        funcA();
    } 
    if(clicks > 1){
        funcB();
    }
    clicks++;
}

Where funcA and func

about 4 years ago · Santiago Trujillo Report

0

Edit: I changed my answer due to your latest addition to your question. See this snippet:

var myFunctions = [];

myFunctions.push(function() {
  $("body").css("background-color", "red");
});

myFunctions.push(function() {
  $("body").css("background-color", "green");
});

$("html, body").click(function(){
  if(myFunctions.length > 0) myFunctions.shift()();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

about 4 years ago · Santiago Trujillo Report

0

html part :

<input type="button" value="Click Me" />

script part:

$("input").one("click",function() {
    alert("First Function");  
  $("input").one("click",function() {
    alert("Second Function");
  });
});

Demo

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!