Reputation: 10068
I have something like this:
var stopwatch = function (item) {
window.setInterval(function () {
item.innerHtml = myInteger++;
}, 1000);
}
This code was supposed to display myInteger
, but it is not updating values of item
. Why (item
is a div with text inside)?
Upvotes: 0
Views: 129
Reputation: 11707
Try this code :
var stopwatch = setInterval(function (item) {
item.innerHtml = myInteger++;
}, 1000);
This should work
Upvotes: 0
Reputation: 191729
There could be a lot of reasons (we need to see more of your code), but here is a working example:
var myInteger = 1,
stopwatch = function (item) {
window.setInterval(function () {
item.innerHTML = myInteger++;
}, 1000);
}
stopwatch(document.querySelector('div'));
Important changes:
stopwatch
(you probably do this)- innerHtml
+innerHTML
(the case matters). You won't get an error for setting innerHtml
; it will set that property and you won't notice anything.myInteger
.Upvotes: 6