-
-
Save lesichkovm/858dfde429e8ff76eace3496964accd4 to your computer and use it in GitHub Desktop.
Hyperscript for jQuery
This file contains 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