title: How to set width of div to another div's width?
body: <p>I'm trying to set, with javascript, the width of one <code>div</code> to the width of another.  In my case, the second <code>div</code> was cloned from the first.</p>
  
  <p>The issue I'm running into is related to padding, and how style.width is defined differently from clientWidth/offsetWidth/scrollWidth.  In my example below, I have two <code>div</code>s defined the same except with different widths.  When the button is pressed, I'm trying to set the width of the smaller one to the bigger one - but the outcome is that it gets the width of the bigger one PLUS the padding (an extra 20px).</p>
  
  <p>Is there a way to change the line:</p>
  
  <pre><code>two.style.width = one.clientWidth + 'px';
  </code></pre>
  
  <p>to make the two <code>div</code>s equal in width?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function setWidth() {
    var one = document.getElementById("one");
    var two = document.getElementById("two");
    two.style.width = one.clientWidth + 'px';
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.outer {
    background: red;
    padding: 10px;
    } 
  .inner {
    background: green;
    height: 10px;
    } 
  
  #one {
    width: 100px; 
  }
  #two {
    width:50px;
      }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id=one class=outer&gt;&lt;div class=inner&gt;&lt;/div&gt;&lt;/div&gt;
  &lt;br&gt;
  &lt;div id=two class=outer&gt;&lt;div class=inner&gt;&lt;/div&gt;&lt;/div&gt;
  &lt;button onclick="setWidth()"&gt;SET WIDTH&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>