On delete confirmation window does not appears in php
<p>Please tell where I am wrong so that I can correct it? Its not giving error it should show confirmation window before it deletes record but it directly deletes record   </p>

<pre><code>&lt;script type="text/javascript"&gt;
var elems = document.getElementsByClassName('confirmation');
    var confirmIt = function (e) {
        if (!confirm('Are you sure?')) e.preventDefault();
    };
    for (var i = 0, l = elems.length; i &lt; l; i++) {
        elems[i].addEventListener('click', confirmIt, false);
    }
&lt;/script&gt;
</code></pre>

<p>Link for delete:</p>

<pre><code>&lt;a href='".$_SERVER['PHP_SELF']."?action=delete&amp;id=$id' class='confirmation'&gt; Delete&lt;/a&gt;
</code></pre>

<p>delete function:</p>

<pre><code>if(isset($_GET['action']) &amp;&amp; trim($_GET['action'])=="delete")
{
$del="delete from contacts where id='".$_GET['id']."'";

mysql_query($del) or die(mysql_error());
header("Location: mainpage.php");
} 
</code></pre>
