Skip to content

Instantly share code, notes, and snippets.

@roccogalluzzo
Created January 26, 2010 15:03
Show Gist options
  • Save roccogalluzzo/286900 to your computer and use it in GitHub Desktop.
Save roccogalluzzo/286900 to your computer and use it in GitHub Desktop.
var Element = {
visible: function() {return (!this.hasClassName('toggle'));},
toggle: function() {if (this.visible()) { this.hide();} else {this.show();}},
hide: function() {this.addClassName('toggle'); return this;},
show: function() { this.removeClassName('toggle'); return this;},
remove: function() { this.getParentNode().removeChild(this);return null;},
empty: function() {while (this.getLastChild()) { this.removeChild(this.getLastChild());}},
bind: function(event, fn){ console.log(event, fn)}
}
function $(element) {
if (typeof element == "string"){
element = document.getElementById(element);
if (element){ extend(element,Element);return element;}}
}
//common functions
function extend(instance,fn) {
for (var name in fn) {
instance[name] = fn[name];
}
}
$('div').hide();
$('div').show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment