Bug in replaceWith?

Bug in replaceWith?

Hello

I've got some code that iterates over a bunch of elements, found by a class and wraps them all with some template html:

  1. $('.'+clazz).each(function () {        
  2.       var element = $(this).clone();
  3.       var wrappedElement = $($(templates[clazz]).children()[0]).clone();
  4.       wrappedElement.find('#content').replaceWith(element);
  5.       // this should just be - $(this).replaceWith(wrappedElement); - jQuery bug?
  6.       if (this.id != '') {  $('#' + this.id).replaceWith(wrappedElement); } else { $(this).replaceWith(wrappedElement); }
    });
line 5 shows that I should just be able to say: $(this).replaceWith(wrappedElement);
but it doesn't work if the element has an id.

Has anyone else seen this? The work-around I have is fine, but surely it shoudln't be that way