Is it possible to call one function after clicking on the body, and then call another function after the second click?
I tried and then stopped, any ideas?
$("html, body").one("click",function() { // to something }
You can try something like this:
var clicks = 0; $("html, body").on("click",function() { if(clicks === 0){ funcA(); } if(clicks > 1){ funcB(); } clicks++; }
Where funcAandfunc
funcA
func
Edit: I changed my answer due to your last 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>
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
Source: https://habr.com/ru/post/1672172/More articles:The console does not contain a definition for ReadKey when using Roslyn - c #How to check the type of REPL you are using? - pythonHow to update Team Team Visual Studio build definition using REST api? - restHow can I run the if run from ipython test in Python? - pythonImport another file error - pythonHow to sort a dictionary in python by value when the value is a list, and I want to sort it by the first index of this list - pythonGoogle Cloud ML FAILED_PRECONDITION - pythonImport error: no module named cloud.ml - pythonVector dot product along one dimension for multidimensional arrays - pythonWhy does firebase 'linkWithPopup () not set the user `photoUrl` in firebase? - firebaseAll Articles