Select image id
<p>I'm trying to grab the  id of the image that is clicked and then submit it with the form (by setting the val of the hidden imagenr input). However I don't know how to pull the id. </p>

<pre><code>    $(document).ready(function () {
            $(".test-img").click(function () {

                var imagevar = // How to grab the clicked img id?
                $("#imagenr").val(imagevar); // set the img id to the hidden input
                $("form#test-form").submit(); // submit the form

            })
        })




&lt;form action="#" method="post" id="test-form"&gt;
&lt;input type="hidden" name="imagenr" id="imagenr" value=""&gt;

&lt;img class="test-img" id="1" src="images/image1.jpg" alt=""/&gt;
&lt;img class="test-img" id="2" src="images/image2.jpg" alt=""/&gt;

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