Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*!
- * get children of a parent element by tag name
- * gist.github.com/englishextra/d4789c5d30f6f6b429fdf7aaebeda7b1
- * based on gist.github.com/mgechev/5fbeca3627fef7bad0de
- */
- function getChildrenByTag(root, tagName) {
- tagName = tagName.toUpperCase();
- root = root || document;
- var stack = [root],
- result = [],
- current,
- node;
- while (stack.length) {
- current = stack.pop();
- for (var i = 0; i < current.children.length; i += 1) {
- node = current.children[i];
- if (node.tagName.toUpperCase() === tagName) {
- result.push(node);
- }
- stack.push(node);
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement