Created
March 21, 2014 18:23
-
-
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
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
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