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!
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.
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.
<!-- 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:
Of course, the semantics of those elements may not be suitable for you, if comments work stick with them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With