Skip to content

Instantly share code, notes, and snippets.

@lesichkovm
Forked from ivanoats/jqh.js
Created November 5, 2017 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesichkovm/858dfde429e8ff76eace3496964accd4 to your computer and use it in GitHub Desktop.
Save lesichkovm/858dfde429e8ff76eace3496964accd4 to your computer and use it in GitHub Desktop.
Hyperscript for jQuery
// 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