if element has an image, wrap it and move it

if element has an image, wrap it and move it

I have a series of divs that may or may not contain an image. I need to check if each div has an image, and if it does, wrap the div, wrap the image, and move the wrapped image into the newly wrapped div (so I can have it float next to the original div).

So from this:

<div class="event">image text</div>
<div class="event">text</div>

to this:

<div class="eventHolder" >
 <div class="imageHolder" >image></div>
 <div class="event" >text</div>
 </div>
<div class="event">text</div>

I feel like I'm close with this code, but it isn't working:

$( “.event” ).each(function( i ) {

      if($(this).has('img')){

      $(this).wrap("<div class='eventHolder'></div>");

       $('.event img').wrap("<div class='imageHolder'></div>");

       $(".imageHolder").prependTo($(this).parent());

      }

});


Thanks for any help!