Javascript getElementById returning string - Stack Overflow

I'm experiencing a problem with getElementById and it's driving me doolaly. I'm expectin

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
Add a ment  | 

2 Answers 2

Reset to default 9

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().

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

相关推荐

  • Javascript getElementById returning string - Stack Overflow

    I'm experiencing a problem with getElementById and it's driving me doolaly. I'm expectin

    12小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信