Skip to content

Instantly share code, notes, and snippets.

@nikolajbaer
Created September 30, 2011 20:41
Show Gist options
  • Save nikolajbaer/1254916 to your computer and use it in GitHub Desktop.
Save nikolajbaer/1254916 to your computer and use it in GitHub Desktop.
Embedded JSON per HTML Elements
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("script[type='application/json']").each(function(){
if(this.attributes["data-wc-name"]!=undefined){
var name = this.attributes["data-wc-name"].value; var o = JSON.parse(this.textContent);
this.parentElement[name]=o;
}
});
});
</script>
</head>
<body>
<div id="blah">
<script type="application/json" data-wc-name="dadata">
{ "kevin":"is a noob", "nikolaj":"is 31337" }
</script>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment