How to make an auto clicker in JavaScript?How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How do I make the first letter of a string uppercase in JavaScript?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?
What Brexit proposals are on the table in the indicative votes on the 27th of March 2019?
How did Doctor Strange see the winning outcome in Avengers: Infinity War?
What does "I’d sit this one out, Cap," imply or mean in the context?
How long to clear the 'suck zone' of a turbofan after start is initiated?
India just shot down a satellite from the ground. At what altitude range is the resulting debris field?
Detecting if an element is found inside a container
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
Is expanding the research of a group into machine learning as a PhD student risky?
Failed to fetch jessie backports repository
Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?
How to Reset Passwords on Multiple Websites Easily?
Is the destination of a commercial flight important for the pilot?
Opposite of a diet
How to draw lines on a tikz-cd diagram
What is paid subscription needed for in Mortal Kombat 11?
How do we know the LHC results are robust?
Escape a backup date in a file name
Anatomically Correct Strange Women In Ponds Distributing Swords
How did Arya survive the stabbing?
How to check is there any negative term in a large list?
System.debug(JSON.Serialize(o)) Not longer shows full string
What happens if you roll doubles 3 times then land on "Go to jail?"
What can we do to stop prior company from asking us questions?
How to pronounce the slash sign
How to make an auto clicker in JavaScript?
How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How do I make the first letter of a string uppercase in JavaScript?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?
I'm currently making a clicker game and I wanted to know how to make a button that when I click on it, a number slowly goes up with intervals. I don't really know how to do the intervals and I've tried doing loops but loops are instant and have no intervals.
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
<button onclick="increase()">
by 1
</button>
<div>
number:
<div id="number">
0
</div>
</div>
Can someone turn this into an auto clicker? as said above, i just want to click on the button once and have the value of the variable "number" go up. Thanks.
javascript html
|
show 1 more comment
I'm currently making a clicker game and I wanted to know how to make a button that when I click on it, a number slowly goes up with intervals. I don't really know how to do the intervals and I've tried doing loops but loops are instant and have no intervals.
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
<button onclick="increase()">
by 1
</button>
<div>
number:
<div id="number">
0
</div>
</div>
Can someone turn this into an auto clicker? as said above, i just want to click on the button once and have the value of the variable "number" go up. Thanks.
javascript html
setTimeout, setInterval.....
– epascarello
Mar 21 at 15:54
Why defer on the script?
– mplungjan
Mar 21 at 15:59
sorry i thought i can make more than 1 answers
– Thomas Tallman
Mar 21 at 16:34
No, alas not. And with more rep you can vote others up
– mplungjan
Mar 21 at 16:37
i hope thats soon because i hate not being able to show my opinion
– Thomas Tallman
Mar 21 at 16:40
|
show 1 more comment
I'm currently making a clicker game and I wanted to know how to make a button that when I click on it, a number slowly goes up with intervals. I don't really know how to do the intervals and I've tried doing loops but loops are instant and have no intervals.
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
<button onclick="increase()">
by 1
</button>
<div>
number:
<div id="number">
0
</div>
</div>
Can someone turn this into an auto clicker? as said above, i just want to click on the button once and have the value of the variable "number" go up. Thanks.
javascript html
I'm currently making a clicker game and I wanted to know how to make a button that when I click on it, a number slowly goes up with intervals. I don't really know how to do the intervals and I've tried doing loops but loops are instant and have no intervals.
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
<button onclick="increase()">
by 1
</button>
<div>
number:
<div id="number">
0
</div>
</div>
Can someone turn this into an auto clicker? as said above, i just want to click on the button once and have the value of the variable "number" go up. Thanks.
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
<button onclick="increase()">
by 1
</button>
<div>
number:
<div id="number">
0
</div>
</div>
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
<button onclick="increase()">
by 1
</button>
<div>
number:
<div id="number">
0
</div>
</div>
javascript html
javascript html
edited Mar 21 at 15:59
mplungjan
89.8k22127184
89.8k22127184
asked Mar 21 at 15:53
Thomas TallmanThomas Tallman
106
106
setTimeout, setInterval.....
– epascarello
Mar 21 at 15:54
Why defer on the script?
– mplungjan
Mar 21 at 15:59
sorry i thought i can make more than 1 answers
– Thomas Tallman
Mar 21 at 16:34
No, alas not. And with more rep you can vote others up
– mplungjan
Mar 21 at 16:37
i hope thats soon because i hate not being able to show my opinion
– Thomas Tallman
Mar 21 at 16:40
|
show 1 more comment
setTimeout, setInterval.....
– epascarello
Mar 21 at 15:54
Why defer on the script?
– mplungjan
Mar 21 at 15:59
sorry i thought i can make more than 1 answers
– Thomas Tallman
Mar 21 at 16:34
No, alas not. And with more rep you can vote others up
– mplungjan
Mar 21 at 16:37
i hope thats soon because i hate not being able to show my opinion
– Thomas Tallman
Mar 21 at 16:40
setTimeout, setInterval.....
– epascarello
Mar 21 at 15:54
setTimeout, setInterval.....
– epascarello
Mar 21 at 15:54
Why defer on the script?
– mplungjan
Mar 21 at 15:59
Why defer on the script?
– mplungjan
Mar 21 at 15:59
sorry i thought i can make more than 1 answers
– Thomas Tallman
Mar 21 at 16:34
sorry i thought i can make more than 1 answers
– Thomas Tallman
Mar 21 at 16:34
No, alas not. And with more rep you can vote others up
– mplungjan
Mar 21 at 16:37
No, alas not. And with more rep you can vote others up
– mplungjan
Mar 21 at 16:37
i hope thats soon because i hate not being able to show my opinion
– Thomas Tallman
Mar 21 at 16:40
i hope thats soon because i hate not being able to show my opinion
– Thomas Tallman
Mar 21 at 16:40
|
show 1 more comment
5 Answers
5
active
oldest
votes
Here is mine showing how to
- use an interval
- use eventListener (unobtrusive coding)
- clear the interval
- how to increment a number and change speed
- how to use data attributes
- how to use classes and querySelector
var number = 0,
increment = 1,
speed=1000, // one second
tId;
function inc()
clearInterval(tId); // stop anything already running
tId = setInterval(function()
document.getElementById("number").innerHTML = number += increment;
, speed);
function changeSpeed()
speed = +this.getAttribute("data-speed"); // get attribute and convert to number
inc();
window.addEventListener("load", function() // when page has loaded
document.querySelectorAll(".start").forEach(function(but)
but.addEventListener("click", function()
increment = +this.getAttribute("data-inc") ; // get from button and convert to number
inc()
);
);
document.getElementById("stop").addEventListener("click", function() // when clicking
clearInterval(tId);
);
document.querySelectorAll(".speed").forEach(function(but)
but.addEventListener("click", changeSpeed);
);
);
<button type="button" class="start" data-inc="1">By 1</button>
<button type="button" class="start" data-inc="10">By 10</button>
<button type="button" class="speed" data-speed="1000">One a sec</button>
<button type="button" class="speed" data-speed="500">Two a sec</button>
<button type="button" id="stop">Stop</button>
<div>
number: <span id="number">0</span>
</div>
1
your answer is very complex and i will use it in the future. good job (:
– Thomas Tallman
Mar 21 at 16:35
Complete, not complex :)
– mplungjan
Mar 21 at 16:35
add a comment |
function increase()
setInterval(() => document.getElementById("number").innerHTML = number += 1, 1000)
setInterval() will call an anonymous function which increment the number each second (1000 ms) until you call clearInterval()
add a comment |
var number = 0;
function increase ()
number++;
document.getElementById('number').innerHTML = number;
Try this out.
I believe the issue is, you're not actually incrementing the variable 'number'. What you're instead doing is setting the content of the element number to number +=1;
So since number is 0;
it will only ever show 1 on the HTML.
If you want the number to increment by one automatically after you've clicked the button once. Create a setInterval.
setInterval(() =>
increase()
, 5000) // increase every 5 seconds
that's a simpler way of what i did but not an auto clicker. but helpful because its neater.
– Thomas Tallman
Mar 21 at 16:00
If you want to make it automatic, do a setInterval. Check out my edit :)
– Lorza
Mar 21 at 16:01
2
setInterval(increase, 5000)
– mplungjan
Mar 21 at 16:06
thanks (: ill use it
– Thomas Tallman
Mar 21 at 16:21
add a comment |
You can set an interval with setInterval();
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
setInterval(increase, 1000);
This should increase the number every second.
If you want to stop it then you can say:
var interval = setInterval(increase, 1000);
clearInterval(interval);
i cant accept the answer now but it worked. SOOOOO simple! thanks!
– Thomas Tallman
Mar 21 at 16:02
ive figured out that it cant get any faster than 1. is there a way to change that?
– Thomas Tallman
Mar 21 at 16:04
@ThomasTallman You mean 1 second or 1 millisecond? If you want it faster than 1 second then reduce the second argument (1000 === 1000 milliseconds === 1 second) If you want it faster than 1ms you'll just have to increase the amount your increment value
– liamgbs
Mar 21 at 16:09
Or even try using two intervals instead?
– liamgbs
Mar 21 at 16:13
ok. so 1000 is milliseconds, which is 1 second. i did 1 milisecond, and i was wondering if there is anything faster than that. EDIT: true. i should just increase the increment
– Thomas Tallman
Mar 21 at 16:22
add a comment |
you can use setInterval(function() //do someting every 3 seconds , 3000);
you can call te function in interval parameter or write the code inside
look tehse examples
https://www.w3schools.com/jsref/met_win_setinterval.asp
1
also worked. thanks!
– Thomas Tallman
Mar 21 at 16:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284406%2fhow-to-make-an-auto-clicker-in-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is mine showing how to
- use an interval
- use eventListener (unobtrusive coding)
- clear the interval
- how to increment a number and change speed
- how to use data attributes
- how to use classes and querySelector
var number = 0,
increment = 1,
speed=1000, // one second
tId;
function inc()
clearInterval(tId); // stop anything already running
tId = setInterval(function()
document.getElementById("number").innerHTML = number += increment;
, speed);
function changeSpeed()
speed = +this.getAttribute("data-speed"); // get attribute and convert to number
inc();
window.addEventListener("load", function() // when page has loaded
document.querySelectorAll(".start").forEach(function(but)
but.addEventListener("click", function()
increment = +this.getAttribute("data-inc") ; // get from button and convert to number
inc()
);
);
document.getElementById("stop").addEventListener("click", function() // when clicking
clearInterval(tId);
);
document.querySelectorAll(".speed").forEach(function(but)
but.addEventListener("click", changeSpeed);
);
);
<button type="button" class="start" data-inc="1">By 1</button>
<button type="button" class="start" data-inc="10">By 10</button>
<button type="button" class="speed" data-speed="1000">One a sec</button>
<button type="button" class="speed" data-speed="500">Two a sec</button>
<button type="button" id="stop">Stop</button>
<div>
number: <span id="number">0</span>
</div>
1
your answer is very complex and i will use it in the future. good job (:
– Thomas Tallman
Mar 21 at 16:35
Complete, not complex :)
– mplungjan
Mar 21 at 16:35
add a comment |
Here is mine showing how to
- use an interval
- use eventListener (unobtrusive coding)
- clear the interval
- how to increment a number and change speed
- how to use data attributes
- how to use classes and querySelector
var number = 0,
increment = 1,
speed=1000, // one second
tId;
function inc()
clearInterval(tId); // stop anything already running
tId = setInterval(function()
document.getElementById("number").innerHTML = number += increment;
, speed);
function changeSpeed()
speed = +this.getAttribute("data-speed"); // get attribute and convert to number
inc();
window.addEventListener("load", function() // when page has loaded
document.querySelectorAll(".start").forEach(function(but)
but.addEventListener("click", function()
increment = +this.getAttribute("data-inc") ; // get from button and convert to number
inc()
);
);
document.getElementById("stop").addEventListener("click", function() // when clicking
clearInterval(tId);
);
document.querySelectorAll(".speed").forEach(function(but)
but.addEventListener("click", changeSpeed);
);
);
<button type="button" class="start" data-inc="1">By 1</button>
<button type="button" class="start" data-inc="10">By 10</button>
<button type="button" class="speed" data-speed="1000">One a sec</button>
<button type="button" class="speed" data-speed="500">Two a sec</button>
<button type="button" id="stop">Stop</button>
<div>
number: <span id="number">0</span>
</div>
1
your answer is very complex and i will use it in the future. good job (:
– Thomas Tallman
Mar 21 at 16:35
Complete, not complex :)
– mplungjan
Mar 21 at 16:35
add a comment |
Here is mine showing how to
- use an interval
- use eventListener (unobtrusive coding)
- clear the interval
- how to increment a number and change speed
- how to use data attributes
- how to use classes and querySelector
var number = 0,
increment = 1,
speed=1000, // one second
tId;
function inc()
clearInterval(tId); // stop anything already running
tId = setInterval(function()
document.getElementById("number").innerHTML = number += increment;
, speed);
function changeSpeed()
speed = +this.getAttribute("data-speed"); // get attribute and convert to number
inc();
window.addEventListener("load", function() // when page has loaded
document.querySelectorAll(".start").forEach(function(but)
but.addEventListener("click", function()
increment = +this.getAttribute("data-inc") ; // get from button and convert to number
inc()
);
);
document.getElementById("stop").addEventListener("click", function() // when clicking
clearInterval(tId);
);
document.querySelectorAll(".speed").forEach(function(but)
but.addEventListener("click", changeSpeed);
);
);
<button type="button" class="start" data-inc="1">By 1</button>
<button type="button" class="start" data-inc="10">By 10</button>
<button type="button" class="speed" data-speed="1000">One a sec</button>
<button type="button" class="speed" data-speed="500">Two a sec</button>
<button type="button" id="stop">Stop</button>
<div>
number: <span id="number">0</span>
</div>
Here is mine showing how to
- use an interval
- use eventListener (unobtrusive coding)
- clear the interval
- how to increment a number and change speed
- how to use data attributes
- how to use classes and querySelector
var number = 0,
increment = 1,
speed=1000, // one second
tId;
function inc()
clearInterval(tId); // stop anything already running
tId = setInterval(function()
document.getElementById("number").innerHTML = number += increment;
, speed);
function changeSpeed()
speed = +this.getAttribute("data-speed"); // get attribute and convert to number
inc();
window.addEventListener("load", function() // when page has loaded
document.querySelectorAll(".start").forEach(function(but)
but.addEventListener("click", function()
increment = +this.getAttribute("data-inc") ; // get from button and convert to number
inc()
);
);
document.getElementById("stop").addEventListener("click", function() // when clicking
clearInterval(tId);
);
document.querySelectorAll(".speed").forEach(function(but)
but.addEventListener("click", changeSpeed);
);
);
<button type="button" class="start" data-inc="1">By 1</button>
<button type="button" class="start" data-inc="10">By 10</button>
<button type="button" class="speed" data-speed="1000">One a sec</button>
<button type="button" class="speed" data-speed="500">Two a sec</button>
<button type="button" id="stop">Stop</button>
<div>
number: <span id="number">0</span>
</div>
var number = 0,
increment = 1,
speed=1000, // one second
tId;
function inc()
clearInterval(tId); // stop anything already running
tId = setInterval(function()
document.getElementById("number").innerHTML = number += increment;
, speed);
function changeSpeed()
speed = +this.getAttribute("data-speed"); // get attribute and convert to number
inc();
window.addEventListener("load", function() // when page has loaded
document.querySelectorAll(".start").forEach(function(but)
but.addEventListener("click", function()
increment = +this.getAttribute("data-inc") ; // get from button and convert to number
inc()
);
);
document.getElementById("stop").addEventListener("click", function() // when clicking
clearInterval(tId);
);
document.querySelectorAll(".speed").forEach(function(but)
but.addEventListener("click", changeSpeed);
);
);
<button type="button" class="start" data-inc="1">By 1</button>
<button type="button" class="start" data-inc="10">By 10</button>
<button type="button" class="speed" data-speed="1000">One a sec</button>
<button type="button" class="speed" data-speed="500">Two a sec</button>
<button type="button" id="stop">Stop</button>
<div>
number: <span id="number">0</span>
</div>
var number = 0,
increment = 1,
speed=1000, // one second
tId;
function inc()
clearInterval(tId); // stop anything already running
tId = setInterval(function()
document.getElementById("number").innerHTML = number += increment;
, speed);
function changeSpeed()
speed = +this.getAttribute("data-speed"); // get attribute and convert to number
inc();
window.addEventListener("load", function() // when page has loaded
document.querySelectorAll(".start").forEach(function(but)
but.addEventListener("click", function()
increment = +this.getAttribute("data-inc") ; // get from button and convert to number
inc()
);
);
document.getElementById("stop").addEventListener("click", function() // when clicking
clearInterval(tId);
);
document.querySelectorAll(".speed").forEach(function(but)
but.addEventListener("click", changeSpeed);
);
);
<button type="button" class="start" data-inc="1">By 1</button>
<button type="button" class="start" data-inc="10">By 10</button>
<button type="button" class="speed" data-speed="1000">One a sec</button>
<button type="button" class="speed" data-speed="500">Two a sec</button>
<button type="button" id="stop">Stop</button>
<div>
number: <span id="number">0</span>
</div>
edited Mar 21 at 16:36
answered Mar 21 at 16:04
mplungjanmplungjan
89.8k22127184
89.8k22127184
1
your answer is very complex and i will use it in the future. good job (:
– Thomas Tallman
Mar 21 at 16:35
Complete, not complex :)
– mplungjan
Mar 21 at 16:35
add a comment |
1
your answer is very complex and i will use it in the future. good job (:
– Thomas Tallman
Mar 21 at 16:35
Complete, not complex :)
– mplungjan
Mar 21 at 16:35
1
1
your answer is very complex and i will use it in the future. good job (:
– Thomas Tallman
Mar 21 at 16:35
your answer is very complex and i will use it in the future. good job (:
– Thomas Tallman
Mar 21 at 16:35
Complete, not complex :)
– mplungjan
Mar 21 at 16:35
Complete, not complex :)
– mplungjan
Mar 21 at 16:35
add a comment |
function increase()
setInterval(() => document.getElementById("number").innerHTML = number += 1, 1000)
setInterval() will call an anonymous function which increment the number each second (1000 ms) until you call clearInterval()
add a comment |
function increase()
setInterval(() => document.getElementById("number").innerHTML = number += 1, 1000)
setInterval() will call an anonymous function which increment the number each second (1000 ms) until you call clearInterval()
add a comment |
function increase()
setInterval(() => document.getElementById("number").innerHTML = number += 1, 1000)
setInterval() will call an anonymous function which increment the number each second (1000 ms) until you call clearInterval()
function increase()
setInterval(() => document.getElementById("number").innerHTML = number += 1, 1000)
setInterval() will call an anonymous function which increment the number each second (1000 ms) until you call clearInterval()
answered Mar 21 at 15:59
Romain V...Romain V...
1163
1163
add a comment |
add a comment |
var number = 0;
function increase ()
number++;
document.getElementById('number').innerHTML = number;
Try this out.
I believe the issue is, you're not actually incrementing the variable 'number'. What you're instead doing is setting the content of the element number to number +=1;
So since number is 0;
it will only ever show 1 on the HTML.
If you want the number to increment by one automatically after you've clicked the button once. Create a setInterval.
setInterval(() =>
increase()
, 5000) // increase every 5 seconds
that's a simpler way of what i did but not an auto clicker. but helpful because its neater.
– Thomas Tallman
Mar 21 at 16:00
If you want to make it automatic, do a setInterval. Check out my edit :)
– Lorza
Mar 21 at 16:01
2
setInterval(increase, 5000)
– mplungjan
Mar 21 at 16:06
thanks (: ill use it
– Thomas Tallman
Mar 21 at 16:21
add a comment |
var number = 0;
function increase ()
number++;
document.getElementById('number').innerHTML = number;
Try this out.
I believe the issue is, you're not actually incrementing the variable 'number'. What you're instead doing is setting the content of the element number to number +=1;
So since number is 0;
it will only ever show 1 on the HTML.
If you want the number to increment by one automatically after you've clicked the button once. Create a setInterval.
setInterval(() =>
increase()
, 5000) // increase every 5 seconds
that's a simpler way of what i did but not an auto clicker. but helpful because its neater.
– Thomas Tallman
Mar 21 at 16:00
If you want to make it automatic, do a setInterval. Check out my edit :)
– Lorza
Mar 21 at 16:01
2
setInterval(increase, 5000)
– mplungjan
Mar 21 at 16:06
thanks (: ill use it
– Thomas Tallman
Mar 21 at 16:21
add a comment |
var number = 0;
function increase ()
number++;
document.getElementById('number').innerHTML = number;
Try this out.
I believe the issue is, you're not actually incrementing the variable 'number'. What you're instead doing is setting the content of the element number to number +=1;
So since number is 0;
it will only ever show 1 on the HTML.
If you want the number to increment by one automatically after you've clicked the button once. Create a setInterval.
setInterval(() =>
increase()
, 5000) // increase every 5 seconds
var number = 0;
function increase ()
number++;
document.getElementById('number').innerHTML = number;
Try this out.
I believe the issue is, you're not actually incrementing the variable 'number'. What you're instead doing is setting the content of the element number to number +=1;
So since number is 0;
it will only ever show 1 on the HTML.
If you want the number to increment by one automatically after you've clicked the button once. Create a setInterval.
setInterval(() =>
increase()
, 5000) // increase every 5 seconds
edited Mar 21 at 16:00
answered Mar 21 at 15:58
LorzaLorza
408
408
that's a simpler way of what i did but not an auto clicker. but helpful because its neater.
– Thomas Tallman
Mar 21 at 16:00
If you want to make it automatic, do a setInterval. Check out my edit :)
– Lorza
Mar 21 at 16:01
2
setInterval(increase, 5000)
– mplungjan
Mar 21 at 16:06
thanks (: ill use it
– Thomas Tallman
Mar 21 at 16:21
add a comment |
that's a simpler way of what i did but not an auto clicker. but helpful because its neater.
– Thomas Tallman
Mar 21 at 16:00
If you want to make it automatic, do a setInterval. Check out my edit :)
– Lorza
Mar 21 at 16:01
2
setInterval(increase, 5000)
– mplungjan
Mar 21 at 16:06
thanks (: ill use it
– Thomas Tallman
Mar 21 at 16:21
that's a simpler way of what i did but not an auto clicker. but helpful because its neater.
– Thomas Tallman
Mar 21 at 16:00
that's a simpler way of what i did but not an auto clicker. but helpful because its neater.
– Thomas Tallman
Mar 21 at 16:00
If you want to make it automatic, do a setInterval. Check out my edit :)
– Lorza
Mar 21 at 16:01
If you want to make it automatic, do a setInterval. Check out my edit :)
– Lorza
Mar 21 at 16:01
2
2
setInterval(increase, 5000)
– mplungjan
Mar 21 at 16:06
setInterval(increase, 5000)
– mplungjan
Mar 21 at 16:06
thanks (: ill use it
– Thomas Tallman
Mar 21 at 16:21
thanks (: ill use it
– Thomas Tallman
Mar 21 at 16:21
add a comment |
You can set an interval with setInterval();
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
setInterval(increase, 1000);
This should increase the number every second.
If you want to stop it then you can say:
var interval = setInterval(increase, 1000);
clearInterval(interval);
i cant accept the answer now but it worked. SOOOOO simple! thanks!
– Thomas Tallman
Mar 21 at 16:02
ive figured out that it cant get any faster than 1. is there a way to change that?
– Thomas Tallman
Mar 21 at 16:04
@ThomasTallman You mean 1 second or 1 millisecond? If you want it faster than 1 second then reduce the second argument (1000 === 1000 milliseconds === 1 second) If you want it faster than 1ms you'll just have to increase the amount your increment value
– liamgbs
Mar 21 at 16:09
Or even try using two intervals instead?
– liamgbs
Mar 21 at 16:13
ok. so 1000 is milliseconds, which is 1 second. i did 1 milisecond, and i was wondering if there is anything faster than that. EDIT: true. i should just increase the increment
– Thomas Tallman
Mar 21 at 16:22
add a comment |
You can set an interval with setInterval();
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
setInterval(increase, 1000);
This should increase the number every second.
If you want to stop it then you can say:
var interval = setInterval(increase, 1000);
clearInterval(interval);
i cant accept the answer now but it worked. SOOOOO simple! thanks!
– Thomas Tallman
Mar 21 at 16:02
ive figured out that it cant get any faster than 1. is there a way to change that?
– Thomas Tallman
Mar 21 at 16:04
@ThomasTallman You mean 1 second or 1 millisecond? If you want it faster than 1 second then reduce the second argument (1000 === 1000 milliseconds === 1 second) If you want it faster than 1ms you'll just have to increase the amount your increment value
– liamgbs
Mar 21 at 16:09
Or even try using two intervals instead?
– liamgbs
Mar 21 at 16:13
ok. so 1000 is milliseconds, which is 1 second. i did 1 milisecond, and i was wondering if there is anything faster than that. EDIT: true. i should just increase the increment
– Thomas Tallman
Mar 21 at 16:22
add a comment |
You can set an interval with setInterval();
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
setInterval(increase, 1000);
This should increase the number every second.
If you want to stop it then you can say:
var interval = setInterval(increase, 1000);
clearInterval(interval);
You can set an interval with setInterval();
var number = 0;
function increase()
for (var i = 0; i < 1; i++)
document.getElementById("number").innerHTML = number += 1
setInterval(increase, 1000);
This should increase the number every second.
If you want to stop it then you can say:
var interval = setInterval(increase, 1000);
clearInterval(interval);
edited Mar 21 at 16:03
answered Mar 21 at 15:58
liamgbsliamgbs
214
214
i cant accept the answer now but it worked. SOOOOO simple! thanks!
– Thomas Tallman
Mar 21 at 16:02
ive figured out that it cant get any faster than 1. is there a way to change that?
– Thomas Tallman
Mar 21 at 16:04
@ThomasTallman You mean 1 second or 1 millisecond? If you want it faster than 1 second then reduce the second argument (1000 === 1000 milliseconds === 1 second) If you want it faster than 1ms you'll just have to increase the amount your increment value
– liamgbs
Mar 21 at 16:09
Or even try using two intervals instead?
– liamgbs
Mar 21 at 16:13
ok. so 1000 is milliseconds, which is 1 second. i did 1 milisecond, and i was wondering if there is anything faster than that. EDIT: true. i should just increase the increment
– Thomas Tallman
Mar 21 at 16:22
add a comment |
i cant accept the answer now but it worked. SOOOOO simple! thanks!
– Thomas Tallman
Mar 21 at 16:02
ive figured out that it cant get any faster than 1. is there a way to change that?
– Thomas Tallman
Mar 21 at 16:04
@ThomasTallman You mean 1 second or 1 millisecond? If you want it faster than 1 second then reduce the second argument (1000 === 1000 milliseconds === 1 second) If you want it faster than 1ms you'll just have to increase the amount your increment value
– liamgbs
Mar 21 at 16:09
Or even try using two intervals instead?
– liamgbs
Mar 21 at 16:13
ok. so 1000 is milliseconds, which is 1 second. i did 1 milisecond, and i was wondering if there is anything faster than that. EDIT: true. i should just increase the increment
– Thomas Tallman
Mar 21 at 16:22
i cant accept the answer now but it worked. SOOOOO simple! thanks!
– Thomas Tallman
Mar 21 at 16:02
i cant accept the answer now but it worked. SOOOOO simple! thanks!
– Thomas Tallman
Mar 21 at 16:02
ive figured out that it cant get any faster than 1. is there a way to change that?
– Thomas Tallman
Mar 21 at 16:04
ive figured out that it cant get any faster than 1. is there a way to change that?
– Thomas Tallman
Mar 21 at 16:04
@ThomasTallman You mean 1 second or 1 millisecond? If you want it faster than 1 second then reduce the second argument (1000 === 1000 milliseconds === 1 second) If you want it faster than 1ms you'll just have to increase the amount your increment value
– liamgbs
Mar 21 at 16:09
@ThomasTallman You mean 1 second or 1 millisecond? If you want it faster than 1 second then reduce the second argument (1000 === 1000 milliseconds === 1 second) If you want it faster than 1ms you'll just have to increase the amount your increment value
– liamgbs
Mar 21 at 16:09
Or even try using two intervals instead?
– liamgbs
Mar 21 at 16:13
Or even try using two intervals instead?
– liamgbs
Mar 21 at 16:13
ok. so 1000 is milliseconds, which is 1 second. i did 1 milisecond, and i was wondering if there is anything faster than that. EDIT: true. i should just increase the increment
– Thomas Tallman
Mar 21 at 16:22
ok. so 1000 is milliseconds, which is 1 second. i did 1 milisecond, and i was wondering if there is anything faster than that. EDIT: true. i should just increase the increment
– Thomas Tallman
Mar 21 at 16:22
add a comment |
you can use setInterval(function() //do someting every 3 seconds , 3000);
you can call te function in interval parameter or write the code inside
look tehse examples
https://www.w3schools.com/jsref/met_win_setinterval.asp
1
also worked. thanks!
– Thomas Tallman
Mar 21 at 16:02
add a comment |
you can use setInterval(function() //do someting every 3 seconds , 3000);
you can call te function in interval parameter or write the code inside
look tehse examples
https://www.w3schools.com/jsref/met_win_setinterval.asp
1
also worked. thanks!
– Thomas Tallman
Mar 21 at 16:02
add a comment |
you can use setInterval(function() //do someting every 3 seconds , 3000);
you can call te function in interval parameter or write the code inside
look tehse examples
https://www.w3schools.com/jsref/met_win_setinterval.asp
you can use setInterval(function() //do someting every 3 seconds , 3000);
you can call te function in interval parameter or write the code inside
look tehse examples
https://www.w3schools.com/jsref/met_win_setinterval.asp
answered Mar 21 at 15:58
Jorge Félix CazarezJorge Félix Cazarez
5515
5515
1
also worked. thanks!
– Thomas Tallman
Mar 21 at 16:02
add a comment |
1
also worked. thanks!
– Thomas Tallman
Mar 21 at 16:02
1
1
also worked. thanks!
– Thomas Tallman
Mar 21 at 16:02
also worked. thanks!
– Thomas Tallman
Mar 21 at 16:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284406%2fhow-to-make-an-auto-clicker-in-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
setTimeout, setInterval.....
– epascarello
Mar 21 at 15:54
Why defer on the script?
– mplungjan
Mar 21 at 15:59
sorry i thought i can make more than 1 answers
– Thomas Tallman
Mar 21 at 16:34
No, alas not. And with more rep you can vote others up
– mplungjan
Mar 21 at 16:37
i hope thats soon because i hate not being able to show my opinion
– Thomas Tallman
Mar 21 at 16:40