In JS we will often use, get the ID of a tag
var aid=document.getelementbyid ("id")
Now, although there is a getelementsbyclassname this method, but this method again IE6 compatibility problems, so insurance or a library to get class
First look at the library
/** * Created by ASUS on 2016/12/4 by Dirk_jian.*/functionGetbyclass (oparent,sclass) {varAele=oparent.getelementsbytagname (' * ')); vararesult=[]; varRe=NewREGEXP (' \\b ' +sclass+ ' \\b ', ' I '); for(vari=0;i<aele.length;i++){//if (aele[i].classname==sclass)//If you have more than one class then you can't detect it.//if (Aele[i].classname.search (sclass)!=-1)//!=-1 proves that it has SCALSS, but only a few letters of class can be done, not fully achieve the purpose if(Re.test (Aele[i].classname))//This is the detection of unrestricted range {Aresult.push (aele[i]); } } returnAresult;}
Then see how to invoke and modify the CSS style of the obtained class tag.
<script src= "Getbyclass.js" ></script> <script>window.onload=function() {Oul=document.getelementbyid ("Div1"); varAdiv1=getbyclass (Oul, ' div2 ')); varAdiv2=getbyclass (Oul, ' Div3 ')); for(vari=0;i<adiv1.length;i++) {Adiv1[i].style.border= ' 1px solid black '; Adiv1[i].style.width= ' 100px '; Adiv1[i].style.height= ' 100px '; } for(vari=0;i<adiv2.length;i++) {Adiv2[i].style.width= ' 100px '; Adiv2[i].style.height= ' 100px '; Adiv2[i].style.border= ' 1px solid pink '; } } </script>
The following are HTML
<Body> <DivID= "Div1"> <Divclass= "Div2"></Div> <Divclass= "Div3"></Div> </Div></Body>
This makes it easy to get the class of a tag.
JS in the method of getting a tag class to seal a library