Skip to content

Instantly share code, notes, and snippets.

@williammalo
Forked from thingsinjars/LICENSE.txt
Created March 10, 2012 00:02
Show Gist options
  • Save williammalo/2009395 to your computer and use it in GitHub Desktop.
Save williammalo/2009395 to your computer and use it in GitHub Desktop.
Chainable DOM Manipulation
//chainify
function(b,a){for(a in b=b.prototype)(function(c,d){b[a]=function(){d=c.apply(this,arguments);return d==undefined?this:d}})(b[a])}
//propertize
function(d){d.prototype.prop=function(a,c,b){if(void 0!==c)this[a]=c;else for(b in a)this[b]=a[b];return this}}
<script>
(function(b,a){for(a in b=b.prototype)(function(c,d){b[a]=function(){d=c.apply(this,arguments);return d==undefined?this:d}})(b[a])})(Element);
(function(d){d.prototype.prop=function(a,c,b){if(void 0!==c)this[a]=c;else for(b in a)this[b]=a[b];return this}})(Element);
document.body.appendChild(
document.createElement('a')
.prop({
'href': 'http://140byt.es/',
'title': 'tiny awsm'
})
.prop('innerHTML', '140byt.es')
.setAttribute('data-monkeys', '∞')
.addEventListener('click', function(){ alert('Urk! Alert!')}, false)
);​
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment