![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
function
hasClass(name,type) {
var r = [];
// Locate the class name (allows for multiple class names)
var re = new RegExp( " (^|\\s) " + name + " (\\s|$) " );
// Limit search by type, or look through all elements
var e = document.getElementsByTagName(type || " * " );
for ( var j = 0 ; j < e.length; j ++ )
// If the element has the class, add it for return
if ( re.test(e[j]) ) r.push( e[j] );
// Return the list of matched elements
return r;
}
var r = [];
// Locate the class name (allows for multiple class names)
var re = new RegExp( " (^|\\s) " + name + " (\\s|$) " );
// Limit search by type, or look through all elements
var e = document.getElementsByTagName(type || " * " );
for ( var j = 0 ; j < e.length; j ++ )
// If the element has the class, add it for return
if ( re.test(e[j]) ) r.push( e[j] );
// Return the list of matched elements
return r;
}