Get attribute from node by name - Node.js DOM

Node.js examples for DOM:Attribute

Description

Get attribute from node by name

Demo Code


function getAttribute(node, name){
  if(node.attributes.length > 0){
    for (iu = 0; iu < node.attributes.length; iu++){
      if(node.attributes[iu].name == name){
        return node.attributes[iu].nodeValue;
      }//from w w w . ja  va  2s . c  o  m
    }
  }
  return undefined;
}

Related Tutorials