Skip to content

Instantly share code, notes, and snippets.

@oskarkrawczyk
Created June 22, 2009 16:30
Show Gist options
  • Save oskarkrawczyk/134059 to your computer and use it in GitHub Desktop.
Save oskarkrawczyk/134059 to your computer and use it in GitHub Desktop.
// Scott Kyle (http://appden.com)
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);
};
// $E('div#theId.theClass').inject(document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment