Skip to content

Instantly share code, notes, and snippets.

@d48
Created March 21, 2014 18:23
Show Gist options
  • Save d48/9692529 to your computer and use it in GitHub Desktop.
Save d48/9692529 to your computer and use it in GitHub Desktop.
API for creating DOM elements with properties. Returns DOM element to append to document
var elInputName = DOMUtil.create({
type: 'input'
, subType: 'textField'
, placeholder: 'Type in your name'
, class: 'myModule--input-name'
, event: {
click: function() { console.log('clicked'); }
, hover: function() { console.log('i am hovered'); }
}
});
document.getElementById('#someElementThatHasDomNodesAlready').appendChild(elInputName);
/* inserts into body with event handlers
<div id="someElementThatHasDomNodesAlready">
<button id="someElementWithHandler">I'm a button</button>
<input type="text" class="myModule--input-name" placeholder="Type in your name" />
</div>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment