Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.