Creating a button with JS : <p>I am trying to create a button and append it to HTML in Javascript.</p>

<p>This is my code:</p>

<pre><code>&lt;html&gt;

    &lt;head&gt;
        &lt;script&gt;
             var btn=document.createElement("button");
             btn.className = "YourClass";
             btn.className += " YourClass2";
             btn.id ='someId';
             document.getElementById("main").appendChild(btn);
        &lt;/script&gt;
    &lt;/head&gt;

    &lt;body&gt;
        &lt;div id = 'main'&gt;
        &lt;/div&gt;
    &lt;/body&gt;

&lt;/html&gt;
</code></pre>

<p>Unfortunately, this does not work and i don't understand why.</p>
