Reputation: 11
I'm experiencing a problem with getElementById and it's driving me doolaly. I'm expecting the function to return the reference to the object and for the purposes of debugging show the object in the console.
The problem is it doesn't, it returns a string, a annoying useless string. There's a chance that after hours of trying to work this out I'm missing something glaring obvious, but could someone point me in the right direction please.
The code below works if just placed directly into the HTML file, but won't if used within a function and doesn't work when testing it on JSFiddle. If someone could enlighten me why it doesn't work on JSFiddle I'm hoping that'll give me in the insight to work it out in the plugin.
JSFiddle : http://jsfiddle.net/dYtxq/
Many thanks.
Upvotes: 1
Views: 2589
Reputation: 33865
It is working just fine, try doing this in you fiddle for instance:
byId('timebar').innerHTML = "Test";
Added it to a version of your fiddle: http://jsfiddle.net/dYtxq/5/
Upvotes: 0
Reputation: 8556
document.getElementById()
is not returning a string, but an object.
console.log()
is writing the string representation of the element. If you want to see the DOM object you can use console.dir()
.
Upvotes: 9