jquery - Javascript - how to update elements inner html? -


i have this:

var stopwatch = function (item) {    window.setinterval(function () {                 item.innerhtml = myinteger++;         }, 1000); } 

this code supposed display myinteger, not updating values of item. why (item div text inside)?

there lot of reasons (we need see more of code), here working example:

var myinteger = 1, stopwatch = function (item) {     window.setinterval(function () {         item.innerhtml = myinteger++;     }, 1000); } stopwatch(document.queryselector('div')); 

important changes:

  • calling stopwatch (you this)
  • - innerhtml +innerhtml (the case matters). won't error setting innerhtml; set property , won't notice anything.
  • initialize myinteger.

http://jsfiddle.net/q4krm/


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -