onClick event doesn't work inside form tag
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
    &lt;/head&gt;
    &lt;script&gt;    
        function removeP2() {
            var parent = document.getElementById("section");
            var child = document.getElementById("p2");
            parent.removeChild(child);
        }
    &lt;/script&gt;
    &lt;body&gt;
        &lt;nav&gt;
            &lt;form&gt;
               &lt;button onclick="removeP2();"&gt;Remove&lt;/button&gt; 
            &lt;/form&gt;
        &lt;/nav&gt;
        &lt;section id="section"&gt;
            &lt;p id="p1"&gt;Paragraph One.&lt;/p&gt;
            &lt;p id="p2"&gt;Paragraph Two.&lt;/p&gt;
        &lt;/section&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>When I click the submit button, the function executes as usual, but after the function executes, the page reloads itself (removed P2 for a second).</p>

<p>I found a solution which is to delete the "Form" inside the "nav" tag, and it works fine. Just want to ask what is the problem cause that, and if I need to have the "Form" tag inside the "nav" tag, which part I need to fix?</p>