Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /*!
  2. * get children of a parent element by tag name
  3. * gist.github.com/englishextra/d4789c5d30f6f6b429fdf7aaebeda7b1
  4. * based on gist.github.com/mgechev/5fbeca3627fef7bad0de
  5. */
  6. function getChildrenByTag(root, tagName) {
  7. tagName = tagName.toUpperCase();
  8. root = root || document;
  9. var stack = [root],
  10. result = [],
  11. current,
  12. node;
  13. while (stack.length) {
  14. current = stack.pop();
  15. for (var i = 0; i < current.children.length; i += 1) {
  16. node = current.children[i];
  17. if (node.tagName.toUpperCase() === tagName) {
  18. result.push(node);
  19. }
  20. stack.push(node);
  21. }
  22. }
  23. return result;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement