Wrap two divs in one container

Wrap two divs in one container

I'm having trouble wrapping two adjacent divs in one parent container. For example take the following html:
  1. <div>
  2. <div class="line"> hi </div>
  3. <div class="line"> hi again </div>
  4. <div class="line"> hi </div>
  5. <div class="line"> hi again </div>
  6. </div>
I need every pair of ".line" divs to be wrapped in a parent div, so it will look like this:
  1. <div>
  2. <div class="new">
  3. <div class="line"> hi </div>
  4. <div class="line"> hi again </div>
  5. </div>
  6. <div class="new">
  7. <div class="line"> hi </div>
  8. <div class="line"> hi again </div>
  9. </div>
  10. </div>
I can't seem to  get .wrap() to work, it will only select the individual .line divs. I also can't use .before() or .after because when I insert the first <div class="new">, jquery automatically closes it. For example this doesn't work:
  1. $(".line:even").before("<div class=\"new\">");
  2. $(".line:odd").after("</div>");
The opening div is automatically closed by jquery on insert, and the closing div is ignored

Anyone know of another way to do it?