San Francisco Bay Area Professional Blog: Traverse/walk DOM tree recursively
2012-12-17 00:17
281 查看
San Francisco Bay Area Professional Blog: Traverse/walk DOM tree recursively
Here is the recursion function to do this:
view sourceprint?
And you call it:
view sourceprint?
Traverse/walk DOM tree recursively
Task definition: You have a DOM tree (startNode which can be the whole document), and need to find first specific tag in this tree.Here is the recursion function to do this:
view sourceprint?
1.
function
findNodeByTag(startNode, tagName) {
2.
if
(startNode.nodeName.toLowerCase() == tagName.toLowerCase())
return
startNode;
3.
var
childList = startNode.childNodes;
4.
for
(
var
i=0; i<childList.length; i++) {
5.
return
findNodeByTag(childList[i], tagName);
6.
}
7.
return
null
;
8.
}
And you call it:
view sourceprint?
1.
findNodeByTag(myDOMobj,
"img"
);
相关文章推荐
- Manually Traverse a DOM Tree Using jQuery | James Wiseman
- 存储区域网(SAN-Storage Area Network)
- 如何在android上打印dom树,render树,display_tree
- Storage area network introduction (SAN)
- python3.2 读写 xml( xml.etree.ElementTree,xml.dom )
- Html convert to DOM Tree
- 存储区域网(SAN-Storage Area Network)
- JavaScript tutorial - DOM nodes and tree
- Bay_Area_Bike_Share_Analysis
- ExtJs基础知识总结:Dom、IFrame和TreePanel、TabPanel(三)
- Traverse Tree iteratively
- 存储区域网(SAN-Storage Area Network)
- XML生成与解析(DOM、ElementTree)
- python对XML的解析 SAX DOM ElementTree
- JB´s trash: Recursive DOM walk with Dojo
- San Francisco Crime Classification(Kaggle)
- Tree Traverse & BST
- java nio: walkFileTree实现文件夹复制移动删除
- Travel From San Francisco to Las Vegas by Motorcycle
- leetcode之Binary Tree Level Order Traverse