title: jQuery change <span> into <label> and add for="" with previous <input> id
body: <p>I have some jQuery to turn selected spans into labels.</p>
  
  <p>The problem I have now is that I need to add in the for="" so that it works as a button (I'm using radio buttons with the input hidden so it's just a box - therefore the label needs to have the id of the input in order to work). I know I need to create a variable but I'm not sure how to write it.</p>
  
  <p>What I need (and correct me if I'm wrong) is a variable that creates the <code>&lt;label&gt;</code> tag + for="" with the id of the previous input within the "".</p>
  
  <p>Now these radio buttons are brought in with a module though the CMS I'm using so I can't target the id name itself as its different every time and generated by the CMS. So the js needs to target the 'previous/parent' input tag.</p>
  
  <p>So this is what I need the final code to look like after the js has run:</p>
  
  <pre><code>&lt;div class="wrapper"&gt;
  &lt;input type="radio" id="radio1" name="radios" value="SML"&gt;
     &lt;label for="radio1"&gt;Small&lt;/label&gt;
  &lt;input type="radio" id="radio2" name="radios" value="MED"&gt;
     &lt;label for="radio2"&gt;Meduim&lt;/label &gt;
  &lt;input type="radio" id="radio3" name="radios" value="LRG"&gt;
     &lt;label for="radio3"&gt;Large&lt;/label &gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Help please!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;/script&gt;
    &lt;script type="text/javascript"&gt; 
    $( document ).ready(function() {
      jQuery.each($(".wrapper span"), function() {
      $(this).replaceWith("&lt;label&gt;" + $(this).text() + "&lt;/label&gt;");
      });
    });
  &lt;/script&gt;</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>input[type=radio] {
      display:none; 
      margin:10px;
  }
  
  input[type=radio] + label {
      display:inline-block;
      margin:0;
      padding: 8px 15px;
      background-color: #eeeeee;
      border-color:none;
   text-transform:uppercase;
   color:#BDBDBD;
   cursor:pointer;
  
  }
  
  input[type=radio]:checked + label { 
     background-image: none;
      background-color:#EBE300;
   color:#454545;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;div class="wrapper"&gt;
   &lt;input type="radio" id="radio1" name="radios" value="SML"&gt;
         &lt;span&gt;Small&lt;/span&gt;
   &lt;input type="radio" id="radio2" name="radios" value="MED"&gt;
         &lt;span&gt;Meduim&lt;/span&gt;
   &lt;input type="radio" id="radio3" name="radios" value="LRG"&gt;
         &lt;span&gt;Large&lt;/span&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>