Added HTML Element Classes
This commit is contained in:
32
common/HTMLElement.js
Normal file
32
common/HTMLElement.js
Normal file
@ -0,0 +1,32 @@
|
||||
HTMLElement.prototype.removeClass || (HTMLElement.prototype.removeClass = function(remove) {
|
||||
var newClassName = "";
|
||||
var i;
|
||||
var classes = this.className.split(" ");
|
||||
for(i = 0; i < classes.length; i++) {
|
||||
if(classes[i] !== remove) {
|
||||
newClassName += classes[i] + " ";
|
||||
}
|
||||
}
|
||||
this.className = newClassName;
|
||||
});
|
||||
|
||||
HTMLElement.prototype.hasClass || (HTMLElement.prototype.hasClass = function(cls) {
|
||||
return (' ' + this.className + ' ').indexOf(' ' + cls + ' ') > -1;
|
||||
});
|
||||
|
||||
HTMLElement.prototype.addClass || (HTMLElement.prototype.addClass = function(add) {
|
||||
if(this.hasClass(add)) return;
|
||||
this.className += ' ' + add;
|
||||
});
|
||||
|
||||
HTMLElement.prototype.toggleClass || (HTMLElement.prototype.toggleClass = function(clazz) {
|
||||
if(this.hasClass(clazz)) {
|
||||
this.removeClass(clazz);
|
||||
} else {
|
||||
this.addClass(clazz);
|
||||
}
|
||||
});
|
||||
|
||||
HTMLElement.prototype.remove || (HTMLElement.prototype.remove = function() {
|
||||
this.parentElement.removeChild(this);
|
||||
});
|
Reference in New Issue
Block a user