title: How do I print part of a rendered HTML page in JavaScript?
body: <p>The JavaScript code window.print() can print the current HTML page.</p>
  
  <p>If I have a div in an HTML page (for example, a page rendered from an <a href="http://en.wikipedia.org/wiki/ASP.NET_MVC_Framework" rel="noreferrer">ASP.NET MVC</a> view), then I want to print the div only.</p>
  
  <p>Is there any jQuery <a href="https://en.wikipedia.org/wiki/Unobtrusive_JavaScript" rel="noreferrer">unobtrusive JavaScript</a> or normal JavaScript code to implement this request?</p>
  
  <p>Making it more clear, suppose the rendered HTML page is like:</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
      &lt;head id="Head" runat="server"&gt;
          &lt;title&gt;
              &lt;asp:ContentPlaceHolder runat="server" ID="TitleContent" /&gt;
          &lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
              &lt;div id="div1" class="div1"&gt;....&lt;/div&gt;
              &lt;div id="div2" class="div2"&gt;....&lt;/div&gt;
              &lt;div id="div3" class="div3"&gt;....&lt;/div&gt;
              &lt;div id="div4" class="div4"&gt;....&lt;/div&gt;
              &lt;div id="div4" class="div4"&gt;....&lt;/div&gt;
          &lt;p&gt;
              &lt;input id="btnSubmit" type="submit" value="Print" onclick="divPrint();" /&gt;
          &lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Then I want to click on the Print button, only printing div3.</p>