title: Pass div to javascript function and change its style
body: <p>I'm trying to pass a div's id to a javascript function that does something simple, like change the background color of the div. </p>
  
  <p>Weird thing is, my code works in the w3schools.com Tryit editor, but not in JSFiddle. It also doesn't work in my compiler (Coda 2). </p>
  
  <p>Is this even the right way of going about this? Here's my code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  function changeBackgroundColor(asdf)
  {
      asdf.style.backgroundColor = "#fff000";
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="myDiv" style="background:red"&gt; this is my div &lt;/div&gt;
  &lt;button onclick="changeBackgroundColor(myDiv)"&gt; Set background color &lt;/button&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and here's the JSFiddle stuff: <a href="http://jsfiddle.net/BH9Rs/" rel="nofollow">http://jsfiddle.net/BH9Rs/</a></p>