Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an HTML tag that can be used anywhere in the DOM?

Tags:

html

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!

like image 388
Josh Davis Avatar asked Sep 05 '10 00:09

Josh Davis


People also ask

How do you access the DOM element in HTML?

The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID with the getElementById() method of the document object. In the Console, get the element and assign it to the demoId variable. Logging demoId to the console will return our entire HTML element.

Can I use any tags in HTML?

They are valid HTML and are rendered by browsers just like any other HTML tag. By default, custom tags are treated like inline elements, eg: <span> . Add a display: block; property in CSS to make them block-level like a <div> . It is completely safe to use custom HTML tags in your web project.


2 Answers

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

like image 150
jtbandes Avatar answered Oct 13 '22 13:10

jtbandes


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.

like image 30
robertc Avatar answered Oct 13 '22 13:10

robertc