+ 1
What' s wrong in this code?
The error is "cannot change property style of null". I can' t understand why it doesn' t work... var l = setInterval(1, o()); var x = 500; function o() { x-- var g = document.getElementById('p'); g.style.height = x + 'px'; if (x <= 100) { clearInterval(l) } }
3 Antworten
+ 4
Wrong argument and wrong sequence of arguments passed into setInterval
setInterval accepts two arguments
The second argument is time in millisecond.
The first argument is a callback function.
When you pass a function as callback, just put the function name. Don't add parenthesis, because parenthesis will execute it and you will be passing the executed result instead.
+ 4
var x = 500;
function o() {
x--
var g = document.getElementById('p');
g.style.height = x + 'px';
if (x <= 100) {
clearInterval(l)
}
}
var l = setInterval(o,1);
try this one.
+ 1
Thanks Labib Hasan and Gordon, I'll try it