Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- createElement: (type, props, children) => {
- let el = document.createElement(type),
- key;
- for (key in props) {
- if (props.hasOwnProperty(key)) {
- if (helpers.shouldAssignVal(key)) {
- el[key] = props[key];
- } else {
- let attr = helpers.camelCaseToDash(key),
- i = 0;
- if (helpers.isArray(props[key])) {
- for (i; i < props[key].length; i++) {
- el.setAttribute(attr, props[key][i]);
- }
- } else {
- el.setAttribute(attr, props[key]);
- }
- }
- }
- }
- if (typeof children !== 'undefined') {
- if (helpers.isArray(children)) {
- for (let y = 0; y < children.length; y++) {
- if (children[y].nodeType) {
- el.appendChild(children[y]);
- }
- }
- } else {
- el.appendChild(children);
- }
- }
- return el;
- }
- let h1 = helpers.createElement('h1', {
- class: 'title',
- id:'title,
- innerText: 'This is a title' // This part will NOT set an attribute, but will set the value of the innerText property of this node.
- });
- <h1 class="title" id="title">This is a title</h1>
- shouldAssignVal: key => {
- return key === 'value' || key === 'innerText' || key === 'innerHtml';
- }
Add Comment
Please, Sign In to add comment