retrieving variables from a jquery each()
<p>I have a list of divs that may or may not have a class "highlight" assigned to them.</p>

<pre><code>&lt;div id='1' class='box'&gt;&lt;/div&gt;
&lt;div id='2' class='box highlight'&gt;&lt;/div&gt;
&lt;div id='3' class='box'&gt;&lt;/div&gt;
</code></pre>

<p>I am using Jquery each() to identify which one has the class highlight assigned to it and grabbing the id.</p>

<pre><code> $('.box').each(function(){
        if ($(this).hasClass('highlight')){
            var id = $(this).attr('id');//get the id    
            console.log('It has the class = ' + id);//this shows correctly 
        }                       
    });

//outside of the each()
    console.log('id = ' + id);//this does not show the id "undefined"
</code></pre>

<p>When I try to retrieve the id outside of the each() it is undefined.  Is there any way of retrieving it?                    </p>
