Skip to content

Instantly share code, notes, and snippets.

@apla
Created October 28, 2013 18:01
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 apla/7201557 to your computer and use it in GitHub Desktop.
Save apla/7201557 to your computer and use it in GitHub Desktop.
make element js function
function MakeEl (name, attributes) {
var el = document.createElement (name);
if (typeof attributes == 'object') {
for (var i in attributes) {
el.setAttribute (i, attributes[i]);
if (i.toLowerCase() == 'class') {
el.className = attributes[i]; // for IE compatibility
} else if (i.toLowerCase() == 'style') {
el.style.cssText = attributes[i]; // for IE compatibility
}
}
}
for (var i = 2; i<arguments.length; i++) {
var val = arguments[i];
if (typeof val == 'string')
val = document.createTextNode( val );
if (el && el.appendChild)
el.appendChild (val);
}
return el;
}
@apla
Copy link
Author

apla commented Oct 28, 2013

var htmlSw = MakeEl (
        'div', {'class': 'html-sw'},
        MakeEl ('input', {type: 'checkbox', id: tid+'-sw', onchange: "SwitchWYSIWYGEditor (this.checked, '"+tid+"')"}),
        MakeEl ('label', {'for': tid+'-sw'}, 'я ламер, дай мне wysiwyg!')
    );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment