title: Check whether an attribute is valid for an element with pure javascript
body: <p>My program dynamically sets attributes on DOM elements. I want to prevent setting incorrect attributes. E.g.:</p>
  
  <pre><code>function set(element,name,value){
      if(name is a bad attribute for element)
        throw 'problem';
      element.setAttribute(name,value);
  }
  </code></pre>
  
  <p>I thought I could use hasAttribute to verify attribute names before setting them, but I can't, because it returns false before I set the attribute first time even for valid attributes. So both things here give false:</p>
  
  <pre><code>button.hasAttribute('typo');
  button.hasAttribute('type');
  </code></pre>
  
  <p>How could I verify that an attribute name is valid?</p>