title: Cross-browser, javascript getAttribute() method?
body: <p>trying to determine a decent, cross browser method for obtaining attributes with javascript? assume javascript library use (jQuery/Mootools/etc.) is not an option.</p>
  
  <p>I've tried the following, but I frequently get "attributes" is null or not an object error when IE tries to use the "else" method. Can anyone assist?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  //...
      getAttr: function(ele, attr) {
        if (typeof ele.attributes[attr] == 'undefined'){
          return ele.getAttribute(attr);
        } else {
          return ele.attributes[attr].nodeValue;
        }
      },
  //...
  &lt;/script&gt;
  
  
  &lt;div&gt;
   &lt;a href="http://www.yo.com#foo"&gt;Link&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>using the above html, in each browser, how do I getAttr(ele, <strong>'href'</strong>)? (assume selecting the ele node isn't an issue)</p>