schema.org.CreateHtml.ByJavaScript.201702140912
Create HTML elements with JSON-LD.
by ytyaru
HTML
<script id="person-ld" type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Person",
"name": "ytyaru",
"url": "https://github.com/ytyaru",
"sameAs": ["http://ytyaru.hatenablog.com/about"]
}
</script>
<body>
</body>
JavaScript
person = JSON.parse(document.getElementById('person-ld').text); document.body.appendChild(createLinkTag(person.name, person.url));
function createLinkTag(text, href)
{
var a = document.createElement('a');
a.appendChild(document.createTextNode(text));
a.setAttribute("href", href);
return a;
}