Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var DomFactory = (function (document) {
- var api = {
- element: function (name, attributes) {
- var el = document.createElement(name);
- if (attributes) {
- for (var key in attributes) {
- if (attributes.hasOwnProperty(key)) {
- el.setAttribute(key, attributes[key]);
- }
- }
- }
- return el;
- },
- div: function (attributes) {
- return api.element('div', attributes);
- }
- };
- return api;
- }(window.document));
- function attach(source, target, position) {
- switch (position) {
- case 'before': {
- target.parentNode.insertBefore(source, target);
- break;
- }
- case 'after': {
- if (target.nextSibling) {
- target.parentNode.insertBefore(source, target.nextSibling);
- } else {
- target.parentNode.appendChild(source);
- }
- }
- }
- }
- /*
- var div = DomFactory.div({ 'class': 'hero' });
- var table = DomFactory.element('table', { 'class': 'table table-bordered' });
- attach(table, div, 'before');
- */
Add Comment
Please, Sign In to add comment