.replaceWith() /.html('..') reach ancestors

.replaceWith() /.html('..') reach ancestors

Hi,

  1. <p id="1"><div class='selected'>this is an example</div></p>
  2. $('.selected').html( '<div class='selected'>this is an example</div> '); 
  3. I get:
  4. <p id="1"><div class='selected'><div class='selected'>this is an example</div></div></p>
  5. and  I can get the closest paragraph outer HTML:
  6. $(this).closest('p').clone().wrap('<p/>').parent().html();
  7. However I want this:
  8. $('.selected').replaceWith( '<div class='selected'>this is an example</div> '); 
  9. to get:
  10. <p id="1"><div class='selected'>this is an example</div></p>
  11. But when I do this I loose the ability to get the div's closest paragraph outer HTML, I can't reach the div ancestors.
Any way to do this?
Thanks,

Regards