click to open image and click to close it
<p>I have a grid of thumbnails and when clicking on any of it, it enlarges.</p>

<p>I could achieve this: open an image (enlarged) and then clicking again to return it to its normal size. Then I clicked again but it is not enlarging. Why is is this happening and how can I solve this?</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$("#thumbs img").click(function() {
 $(this).addClass("enlarge");
 $("#thumbs img").click(function() {
  $(this).removeClass("enlarge");
 });
});</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>#thumbs {
   max-height: 400px;
   overflow-y: auto;
   cursor: pointer;
   width: 300px;
}

#thumbs &gt; img {
   cursor: pointer;
   float: left;
   margin: 1px 1px 1px 1px;
}

.enlarge {
   transform:scale(3,3);
   transform-origin:0 0;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="thumbs"&gt;        
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;
   &lt;img class="thumbnail" src='http://www.mariajuliaolivan.com.ar/wp-content/uploads/2013/12/random-1000x600.jpg' alt="arrow" height="40" width="60"&gt;           
 &lt;/div&gt;</code></pre>
</div>
</div>
</p>