I’m coding a jQuery plugin which is basically run on a single <div>. I’m considering providing configuration values for it using plugin-specific <meta> tags inside the <div>.
Is it valid HTML5 if I put <meta> tags inside the document body, and is it reasonably safe that old browsers won’t move all <meta> tags to the head when parsing the page?
data- attributes are a good solution, but I plan to have a lot of them, so I though something like <meta> would be neater.
The
<meta>element is only valid in the<head>of an HTML5 document (Metadata content model is only acceptable in the<head>). What you should be using for an HTML5 jQuery plugin to pass configuration data is to usedata-*attributes which can be accessed from jQuery using.data().So your markup could be:
And your jQuery would be:
Which would be a function that uses:
In reply to OPs comment:
There’s no limit to how many
data-*attributes you use, if it’s simply for formatting, split them on multiple lines. White space is condensed in HTML:If you have a good reason to keep the data separate from the
<div>you could use an<input>field withtype="hidden"I typically use this when I have an interactive form widget that needs to be submitted with a form.