title: Get full (and original) text of an HTML element
body: <p><strong>Edit:</strong> It looks like we identified the solution to this problem via the comments -- which is achieved by getting value of the <em>.outerHTML</em> property. However, it still appears that at least Firefox and Chrome "normalize" original source code when outerHTML is used. For example, outerHTML of</p>
  
  <pre><code>&lt;div id = "a"&gt;    &lt;!-- string is 14 characters long //--&gt;
  </code></pre>
  
  <p>still returns</p>
  
  <pre><code>&lt;div id="a"&gt;      &lt;!-- string is 12 characters long //--&gt;
  </code></pre>
  
  <p>Apparently, the problem would be considered solved if the formatting of the resulting string would match that of the original HTML source code. Ah! Why must outerHTML adjust the original value?</p>
  
  <p>--- Having said this: ---</p>
  
  <p>I'm looking for a solution to get full text of a clicked HTML tag.</p>
  
  <p>Starting point examples (note <em>intentional</em>, <em>legal</em> but mangled formatting):</p>
  
  <pre><code>&lt;div id = "a" style ="color: blue ;"&gt;text&lt;/div&gt;
  
  // Returns: div
  var doc = document.getElementById("id").tagName;
  
  // Returns: array of attribute name/value pair (without = or ")
  var attrs = document.getElementById("id").attributes;
  </code></pre>
  
  <p>How would we go about generating the following text string, when element #a is clicked:</p>
  
  <pre><code>&lt;div id = "a" style= "color: blue ;"&gt;
  </code></pre>
  
  <p>I seem to have not found a solution for this as of yet.</p>
  
  <p><strong>What's this for?</strong></p>
  
  <p>Ultimately, the goal is to determine the length in characters of the <em>arbitrary</em> contents of a tag. Assuming it can be edited in any way that produces acceptable HTML output. For example, the two cases below should return:</p>
  
  <pre><code>&lt;div id=a style="color:blue"&gt;            // 28
  &lt;div id = "a" style= "color: blue ;"&gt;    // 36
  </code></pre>
  
  <p>Counting is the easy part. It's getting the actual string of that tag, just as it appears in the source code, that is the problem.</p>