title: Why jquery .val() function is not setting a real value?
body: <p>I use this function to check for the presence of attributes:</p>
  
  <pre><code>var hasAttribute = function(el, attr) {
      if ("hasAttribute" in el) {
          return el.attributes[attr] != null;
      }
      else if ("outerHTML" in el) {
          return (el.outerHTML
                     .replace(el.innerHTML, "")
                     .indexOf(" " + attr + "=") &gt; -1);
      }
  };
  </code></pre>
  
  <p>The problem is when I set an input value using <code>.val(x)</code>, I can get the value if I use <code>.val()</code> but <code>hasAttribute</code> function cannot detect it. <a href="http://jsfiddle.net/8HAdA/" rel="nofollow">This jsfiddle</a> shows the problem (I expected that first alert say "input has a value" and second shows it, but in Chrome at least first alert says "input needs a value").</p>
  
  <p>How to make <code>.val(x)</code> work as expected? (Or how to make <code>hasAttribute</code> detect these kind of values)</p>