This article shares with you the code that uses recursive thinking to obtain all tag elements on the page. Friends in need can refer to this code
var tag = []; var search = function($element, tag){ var localName = $element[0].localName; if(!tag.includes(localName)){ tag.push($element[0].localName); } var children = $element.children(); if(children.length > 0) { children.each(function(e){ search($(this), tag); }); } return tag; }; tag = search($('html'), tag); console.log(tag);
Use recursive thinking to traverse all elements and finally return an array
Related recommendations:
Two methods to create multi-level directories in PHP
The above is the detailed content of Recursive thinking to obtain all tag elements on the page (remove duplication). For more information, please follow other related articles on the PHP Chinese website!