2015-12-08 07:17:46 +00:00
|
|
|
// on définit le "indexOf" pour <HTMLCollection> et <NodeList>
|
|
|
|
NodeList.prototype.indexOf = HTMLCollection.prototype.indexOf = function(searchedElement){
|
|
|
|
for( var i = 0 ; i < this.length ; i++ ) // on parcours la collection
|
|
|
|
// si on trouve l'élement, on retourne son rang
|
|
|
|
if( this[i] == searchedElement ) return i;
|
|
|
|
|
|
|
|
// si on a rien trouvé, on retourne -1
|
|
|
|
return -1;
|
2015-12-08 07:50:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function addClass(el, pClass){
|
|
|
|
if( el.className.length > 0 && el.className != pClass ) el.className = el.className + ' ' + pClass;
|
|
|
|
else el.className = pClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
function remClass(el, pClass){
|
|
|
|
if( el.className.indexOf(pClass) > -1 ) // si la class de l'élement contient la classe à enlever
|
|
|
|
el.className = el.className.substr(0, el.className.indexOf(pClass)) + '' + el.className.substr(el.className.indexOf(pClass)+pClass.length);
|
|
|
|
}
|