tags:

views:

109

answers:

3

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 would 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!

+4  A: 

<!-- 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.

jtbandes
Funny, I was just thinking the same thing. Now I have to check if they can be grabbed with `getElementsByTagName()`... perhaps `getElementsByTagName('#comment')` ?
Josh Davis
+1 we are using a specific comment to track a user insertion point.
peterchen
getElementsByTagName() is not supposed to support comments. I'll edit this answer to mention it.
Josh Davis
Hey, where did the comment about comments not being tags go? I would have definitely plus'ed that. Comments don't use HTML *tags*, they're their own type, which is why `getelementsByTagName()` isn't supposed to select them, although some implementations incorrectly allow it.
Josh Davis
Small note: putting a comment above the doctype will cause quirks mode in IE. Shouldnt be a problem here, though..
Paul Irish
+1  A: 

Come to think of it, comments can be used anywhere, although I'm not sure they qualify as a proper tag.

Josh Davis
+1  A: 

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:

Of course, the semantics of those elements may not be suitable for you, if comments work stick with them.

robertc