javascript lookup with specified tag and class value

created at 07-15-2021 views: 1

usage

function getClass(tagName,className)
//Get the element whose tag name is tagName and class name is className
{
    if(document.getElementsByClassName) 
    {        return document.getElementsByClassName(className);
    }
    else
    {       var tags=document.getElementsByTagName(tagName);//Get the label
        var tagArr=[];//Used to return the element whose class name is className
        for(var i=0;i < tags.length; i++)
        {
            if(tags[i].class == className)
            {
                tagArr[tagArr.length] = tags[i];//Save the elements that meet the conditions
            }
        }
        return tagArr;
    }
}


var blogs = getClass('div','c8Bms hMNMsd')
var blog_names=[]
for(var i=0;i < topMenus.length; i++)
{
    blog_names.push(blogs[i].innerHTML);        
}
Please log in to leave a comment.