Skip to content

Instantly share code, notes, and snippets.

@javascripter
Created September 14, 2008 00:52
Show Gist options
  • Save javascripter/10675 to your computer and use it in GitHub Desktop.
Save javascripter/10675 to your computer and use it in GitHub Desktop.
function $N(name, a)
[[i == "className" ? "class": i, a[i]]
for (i in a) if (a.hasOwnProperty(i))]
.reduce((function(elem, [attr, value])
(elem.setAttribute(attr, value), elem)),
document.createElement(name));
$N("div", {className: "foo", id: "bar"}); // <div id="bar" class="foo">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment