Rdfa-implementors-guide

From RDFaWiki

Jump to: navigation, search


JavaScript

Getting at the xmlns attributes, as per [1]. Simplified for just the core piece, assuming a non-null element with a set of attributes.

function get_attr(element, attr) {
  if (element.attributes[attr])
     return element.attributes[attr].value;

  // in Opera, one has to loop through the attributes
  var attributes = element.attributes;
  for (var i=0; i<attributes.length; i++) {
    if (attributes[i].name == attr)
      return attributes[i].value;
  }
}

This works in HTML and XHTML modes in FF3.5, Chrome, Safari4, Opera, and IE7 (the HTML version, not the XHTML version since IE doesn't support that mime type.)

See [2] and [3]