I've been working on a simple counter to practice closures in JavaScript, and I'm struggling with an error that I can't seem to solve. I thought assigning the variable elem to the id of canv would do the trick, but clearly something isn't right. Can anyone point out what's going wrong here?
This is my HTML:
<body>
<div id="canv">
</div>
</body>
This is my JavaScript:
function setup(delay) {
var el = document.getElementById('canv');
counterFn(el, delay);
}
function counterFn(el, delay) {
var counter = 0;
setInterval(getTime, delay);
function getTime(el) {
el.innerHTML(counter);
counter++;
}
}
setup(500);
It all seems quite basic, yet I can't pinpoint where I'm going astray.
Check out my JSFiddle for a clearer picture: https://jsfiddle.net/8sjaqdrh/2/