Created
December 10, 2015 04:32
-
-
Save ivanoats/9f7a3f136a93d965fb17 to your computer and use it in GitHub Desktop.
Hyperscript for jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hyperscript for jQuery | |
// create nested HTML elements with a DSL | |
// used to create reusable, interactive HTML components | |
// | |
// based on the many implentations out there like | |
// https://github.com/dominictarr/hyperscript | |
// https://github.com/Matt-Esch/virtual-dom/tree/master/virtual-hyperscript | |
// and Elm https://github.com/evancz/elm-html | |
var $h = function(element, properties, content) { | |
var $component = $('<' + element + '>'); | |
var props = props || properties || []; | |
props.forEach(function(prop) { | |
$component.attr(prop); | |
}); | |
if (typeof content === 'object') { | |
$component.append(content); | |
} else { | |
$component.text(content); | |
} | |
return $component; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e.g.