Is there an HTML tag that can be used anywhere in the DOM?
This sounds a bit like a trivia question, but it would help me figure out my options solving an actual problem. Is there an HTML tag that can be used anywhere in the DOM? (something to be used as a placeholder) An HTML5 tag w开发者_StackOverflow中文版ould be ok. No XHTML unfortunately.
I've thought about it for a bit, the only tag I can come up with is <script/>
. Otherwise, I guess that <span/>
would work almost(?) anywhere in <body/>
and <meta/>
would work in <head/>
. Any other idea? I haven't thoroughly checked HTML5, so perhaps I'm missing a newer addition.
Also, please don't overthink this and try to reverse-engineer my question. Using a tag as placeholder is one of many different options that I'm examining, that's all. Thanks!
<!-- this one -->
Comments cannot be retrieved using DOM's getElementsByTagName()
. However, it is possible to select them in XPath using the node test comment()
, e.g. //comment()
would select all the comments in the document.
You mentioned that you'd not looked in detail at HTML5, and you've already accepted the comment answer, but I thought I'd mention that most of the elements that come under metadata content would be valid. You can only use base and title within the head element, but all the rest are also valid in the body:
- command
- link (with itemprop attribute for body)
- meta (with itemprop attribute for body)
- noscript
- script
- style (with scoped attribute for body)
Of course, the semantics of those elements may not be suitable for you, if comments work stick with them.
Come to think of it, comments can be used anywhere, although I'm not sure they qualify as a proper tag.
精彩评论