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 : /
Many thanks.
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/dYtxq/
Many thanks.
Share Improve this question asked Jan 5, 2012 at 12:25 FenricFenric 111 silver badge2 bronze badges 1- I don't get it. your code seems to be working – David Hedlund Commented Jan 5, 2012 at 12:28
2 Answers
Reset to default 9document.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()
.
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/dYtxq/5/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744781201a4593350.html
评论列表(0条)