Skip to content

Instantly share code, notes, and snippets.

@hidekiy
Created June 2, 2013 15:15
Show Gist options
  • Save hidekiy/5693808 to your computer and use it in GitHub Desktop.
Save hidekiy/5693808 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jquery-elementize</title>
<style>
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.js"></script>
<script>
function elementize(node) {
var html = node[0],
props = node[1],
children = (props && props.children) || [];
if (props) {
delete props.children;
}
var $el = $(html, props).append(children.map(function (item) {
return elementize(item);
}));
return $el[0]
}
$('body').append(elementize(
['<div/>', {children: [
['<section/>', {children: [
['<p/>', {text: 'foobar', click: function () { alert('foobar'); }}],
['<hr/>'],
['<p/>', {text: 'hogehoge', css: {color: 'blue'}}]
]}]
]}]
));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment