最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get ID of HTML element? - Stack Overflow

programmeradmin1浏览0评论

So the code below will get the ID of the BODY elementL

var bodyId = document.body.id;

How can I get the ID of the HTML element using plain ole' JavaScript?

So the code below will get the ID of the BODY elementL

var bodyId = document.body.id;

How can I get the ID of the HTML element using plain ole' JavaScript?

Share Improve this question asked Jul 14, 2011 at 2:19 CofeyCofey 11.4k16 gold badges54 silver badges75 bronze badges 3
  • Umm...you just did? - which HTML element do you want the Id of? – slandau Commented Jul 14, 2011 at 2:20
  • 1 @slandau: No, that's the ID of the body element. The OP wants the ID of the html element. – icktoofay Commented Jul 14, 2011 at 2:21
  • ooooh, the html tag. i refer to them as tags not elements. i refer to an html element - anything on the page that's valid – slandau Commented Jul 14, 2011 at 2:23
Add a comment  | 

2 Answers 2

Reset to default 12

document.documentElement.id

document.getElementsByTagName('HTML')[0].id
发布评论

评论列表(0)

  1. 暂无评论