title: Getting and Setting the width of an element with Javascript
body: <p>I have a ul list element that varies in width with the text inside it, that changes regularly. Now I want to set the width of the ul list to the width of the first list element, which is text that could change. I want to 'get' the width of the first list item(#item1) and 'set' the width of the ul list (#myList) to that width of the first list item just mentioned. I tried the following code but it does not work:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    var width = document.getElementById('item1').offsetWidth;
    document.getElementById('myList').style.width = width;
  &lt;/script&gt; 
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;ul id="myList"&gt;
    &lt;li id="item1"&gt;text1&lt;/li&gt;
    &lt;li&gt;text2&lt;/li&gt;
    &lt;li&gt;text3&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Any suggestions? I would prefer to Not use jquery, but pure javascript...</p>
  
  <p>Thanks!</p>