This article describes the JavaScript implementation method to obtain the class in the dom. Share it for your reference. The specific implementation method is as follows:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <script> function getClass(node,classname) { if(node.getElementsByClassName) { return node.getElementsByClassName(classname); //Return if this tag exists} else { var elems = node.getElementsByTagName(node), default = []; for (var i = 0; i < elems.length; i++) { //Transfuse all tags if(elems[i].className.indexOf(classname) != -1) { //Find the tags for the corresponding class name default[defualt.length] = elems[i]; } } return default; } } window.onload = function () { var text = document.getElementById('text'), cs = getClass(text,'cs'); document.write(cs.innerHTML='cs'); } </script></head><body> <div id="text"><div>textcss</div></div></body></html>I hope this article will be helpful to everyone's JavaScript programming.