0

I'm implementing a system for my customer along the lines of attaching a tracking element to the DOM whenever specific errors are thrown (it simply has to have a certain value in a data-trkError attribute). My first thought was to use a

<span data-trkError="BLAH" style="display: none;"></span>

But then it occurred to me that this feels intuitively like what the meta tag should be usable for. However, this pretty much needs to be appended to a specific div in the DOM, ie within the body. Is this a problem? Is there anything standard-breaking or not-best-practises about a meta tag in the body tree?

Cheers

unwitting
  • 3,346
  • 2
  • 19
  • 20

2 Answers2

2

I agree that meta would fit better than an empty span. However (even if you could use them in body), note that you can’t just use custom meta keywords. In HTML5, only defined/registered values are valid.

But you can have meta elements in body, if they are used for Microdata or RDFa. For example, RDFa extends HTML5:

If the @property RDFa attribute is present on the link or meta elements, they MUST be viewed as conforming if used in the body of the document. More specifically, when link or meta elements contain the RDFa @property attribute and are used in the body of an HTML5 document, they MUST be considered flow content.

So you could create (or reuse an existing) vocabulary for your metadata. But, depending on your use case, this might be overkill.

As an alternative to span I’d use the script element as data block:

The script element allows authors to include dynamic script and data blocks in their documents. The element does not represent content for the user.

For example:

<script type="text/plain"> <!-- or whichever MIME type suits your need -->
  <!-- your data -->
  <!-- you could of course use data-* attributs on this script element, too -->
</script>
Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360
1

The <meta>-tag is part of the 4.2 Document metadata. Therefor it can only appear in the <head>-section of a document. Your solution using a <span> or a <div> or even a list for multiple errors is just fine for your purpose.

insertusernamehere
  • 23,204
  • 9
  • 87
  • 126