Check if the clicked div id matches with variable
<p>I'm a coding newbie and looking for a way to check in jQuery whether the name of a certain variable corresponds to the ID of a div, and if so fire some code. Unfortunately, something about my syntax is off, and I can't figure out what.</p>

<p>For a simple example, I want to click a div and store the ID of the div as a variable, and if I click it again the variable gets cleared. Simply assigning another boolean variable is not possible due to the rest of the code, I require the ID-check-thingy or something similar.</p>

<p>This is what I have got so far:</p>

<pre><code>&lt;div class="testdiv" id="primary"&gt;Bananarama&lt;/div&gt;
</code></pre>

<pre class="lang-js prettyprint-override"><code>$(document).ready(function() {
    $(".testdiv").click(function() {
        if ($(this).attr("id") == "#" + clickedElement) {     
            // if the ID of the clicked div matches the variable, proceed. This is the part that doesn't seem to work
            alert ("Victory"); // display alert so we know everything worked out
            var clickedElement = null; // reset the variable
        } else {
            var clickedElement = $(this).attr("id"); // the div has been clicked, assign its ID to the variable
        }
    });
});
</code></pre>