上次回来以后一直对DOM的manipulation念念不忘。每次遇到有关的题就看了又看。
Define a walk_the_DOM function that visits every node of the tree in HTML source order, starting from some given node.
- 当然是用recursion来做。Each recursive call is given a smaller piece of the tree to work on.
- It invokes a function, passing it each node in turn.
- walk_the_DOM calls itself to process each of the child nodes.
- Code:
Define a getElementsByAttribute function. It takes an attribute name string and an optional matching value.
- 利用上面的walk_the_DOM. 传入的是DOM中<body>所在的node,以及一个检查node的attribute是不是和要求的att的value相符合的匿名函数。
- 结果存在一个数组里。
- Code:

你看其实又用到了nodeType的概念所以没文化真可怕啊!

[…] More about DOM […]
LikeLike