jQuery - traversing up one parent and setting the ID
<p>I'm trying to grab the text within a label - and traverse it up to the parent("li") and set it as an ID there.</p>

<p>It's getting the text correctly for each iterations - however I'm having issues trying to set it as an ID.</p>

<pre><code>&lt;script&gt; 
    $('.collapse li label').each(function() {
       var test = $(this, '.collapse li label').text();
       $(this, '.collapse li label').parent("li").attr("id", test );
    });
&lt;/script&gt;
</code></pre>

<p>I've also tried:</p>

<pre><code>$('.collapse li').attr("id", test);
</code></pre>

<p>And lastly:</p>

<pre><code>$( this ).parent('li').attr("id", test);
</code></pre>

<p>To no avail.</p>

<p>Please help me understand the correct way of looking at this?</p>

<p>Please see the picture below to better show what it is; i'm trying to achieve:</p>