traversal.js 547 B

123456789101112131415161718192021222324
  1. var getChildren = exports.getChildren = function(elem){
  2. return elem.children;
  3. };
  4. var getParent = exports.getParent = function(elem){
  5. return elem.parent;
  6. };
  7. exports.getSiblings = function(elem){
  8. var parent = getParent(elem);
  9. return parent ? getChildren(parent) : [elem];
  10. };
  11. exports.getAttributeValue = function(elem, name){
  12. return elem.attribs && elem.attribs[name];
  13. };
  14. exports.hasAttrib = function(elem, name){
  15. return !!elem.attribs && hasOwnProperty.call(elem.attribs, name);
  16. };
  17. exports.getName = function(elem){
  18. return elem.name;
  19. };