Find class
function Getelementsbyclassname (parent,tagname,classname) {
var aele=parent.getelementsbytagname (tagName);
var arr=[];
for (var i=0; i<aele.length; i++)
{
var aclassname=aele[i].classname.split ('); //.................... (Subject to a space) at the time of splitting
for (var j=0; j<aclassname.length; J + +)
{
if (aclassname[j]==classname)
{
Arr.push (Aele[i]);
Break //............................. If you find one, jump out of the loop
}
}
}
return arr;
}
Determine if there are duplicates to use in conjunction with the Add class and delete class.
function Arrindexof (arr,v)
{
for (var i=0; i<arr.length; i++)
{
if (ARR[I]==V)
{
return i;
}
}
return-1;
}
Add Class function
function AddClass (obj,classname)
{
if (obj.classname== ')//........ .......... Determine if the object originally has no class to add the class directly
{
Obj.classname=classname;
}
else{
var arr2=obj.classname.split (');
var cun=arrindexof (arr2,classname);
if (Cun = =-1) {//... ...... ..... .......... The judging object didn't have this class and then added
Obj.classname + = ' +classname;
}
}
}
Delete a class function
function Removeclass (obj,classname)
{
if (obj.classname! = ")
{
var arr2=obj.classname.split (');
var cun=arrindexof (arr2,classname);
if (cun! =-1) {
Arr2.splice (cun,1); .... Splice (INDEX,HOWMANY,ITEM1), .......---------------------------()
Obj.classname=arr2.join (");
}
}
}
Knowledge Points:
Splice (INDEX,HOWMANY,ITEM1)
Index: Required. An integer that specifies the location of the Add/remove item, using a negative number to specify the position from the end of the array.
Howmany: Required. The number of items to delete. If set to 0, the item is not deleted.
Item1: Optional. Adds a new item to the array.
Add class, delete class, find class