Node.js examples for DOM:Element
Set and get element attribute
function SetAttribute( element, attName, attValue ) { if ( attValue == null || attValue.length == 0 ) element.removeAttribute( attName, 0 ) ; // 0 : Case Insensitive else/*from ww w .j av a 2 s .c om*/ element.setAttribute( attName, attValue, 0 ) ; // 0 : Case Insensitive } function GetAttribute( element, attName, valueIfNull ) { var oAtt = element.attributes[attName] ; if ( oAtt == null || !oAtt.specified ) return valueIfNull ? valueIfNull : '' ; var oValue ; if ( !( oValue = element.getAttribute( attName, 2 ) ) ) oValue = oAtt.nodeValue ; return ( oValue == null ? valueIfNull : oValue ) ; }