Skip to content

Instantly share code, notes, and snippets.

@appden
Created April 7, 2009 20:08
Show Gist options
  • Save appden/91433 to your computer and use it in GitHub Desktop.
Save appden/91433 to your computer and use it in GitHub Desktop.
function $E(tag, props) {
if (typeof props == 'string')
props = { style : props };
if (typeof tag == 'string') {
var id = tag.match(/#([\w-]+)/);
var classes = tag.match(/(?:\.[\w-]+)+/);
tag = tag.replace(/[#.].*/, '');
props = props || {};
if (id) props.id = id[1];
if (classes) props['class'] = classes[0].replace(/\./g, ' ');
}
return new Element(tag || 'div', props);
};
/*
Please see for more info:
http://appden.com/javascript/element-creation-shortcut-in-mootools/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment