1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
var ls= getElementBySelector('div.code');
//Récupérer tous les tags
function getElementsBySelector(selector){
//Extracted from nifty.js
var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];
if(selector.indexOf(" ")>0){ //descendant selector like "tag#id tag"
s=selector.split(" ");
var fs=s[0].split("#");
if(fs.length==1) return(objlist);
f=document.getElementById(fs[1]);
if(f) return(f.getElementsByTagName(s[1]));
return(objlist);
}
if(selector.indexOf("#")>0){ //id selector like "tag#id"
s=selector.split("#");
tag=s[0];
selid=s[1];
}
if(selid!=""){
f=document.getElementById(selid);
if(f) objlist.push(f);
return(objlist);
}
if(selector.indexOf(".")>0){ //class selector like "tag.class"
s=selector.split(".");
tag=s[0];
selclass=s[1];
}
var v=document.getElementsByTagName(tag); // tag selector like "tag"
if(selclass=="")
return(v);
for(i=0;i<v.length;i++){
if(v[i].className.indexOf(selclass)>=0)
objlist.push(v[i]);
}
return(objlist);
} |
Partager