Element.prototype = {
hasClass : function(className){
return this.className.contains(className, ' ');
},
getId: function(){
return this.id;
}
};
individually if it works
String.prototype.contains = function(item, from){
return this.indexOf(item, from) != -1;
};
Element.prototype.hasClass = function(className){
return this.className.contains(className, ' ');
};
Element.prototype.getId = function() {
return this.id;
};
document.body.innerHTML=document.getElementById('foo').hasClass('blah');
<div id="foo" class="blah"></div>
It is the first time I deal with prototype