Rate this script:  I Love it  /   I Hate it

Get element attributes by namespace


Code


function elementAttributesNS(e, ns) {
  if (!this.__namespaceRegexps)
    this.__namespaceRegexps = {};
  var regexp = this.__namespaceRegexps[ns];
  if (!regexp) {
    this.__namespaceRegexps[ns] = regexp =
    ns ? eval("/^" + ns + ":(.+)/") : /^([^:]*)$/;
  }
  var result = {};
  var atts = e.attributes;
  var l = atts.length;
  for (var i = 0; i < l; i++) {
    var m = atts[i].name.match(regexp);
    if (m)
      result[m[1]] = atts[i].value;
  }
  return result;
}
 

 

 
Get element attributes by namespace scripts | Get element attributes by namespace snippet | Get element attributes by namespace example | Get element attributes by namespace tutorial | Get element attributes by namespace code