When you use each statement, it returns this as a DOM element, not a jQuery object. .html() must be called in a jQuery object. So, the first part of your fix is ββto convert this to a jQuery element with the $ symbol.
$(this).html();
The second problem is that html() returns a string. You cannot call AppendTo() on a string, only a jQuery object. Since you are working with .html() , I assume that you need the contents of the string, not the full contents. If so, Rob's answer is more appropriate.
this.textContent = $(this).prev().html() + this.textContent;
The final code is as follows:
$('font+font').each(function() { this.textContent = $(this).prev().html() + this.textContent; $(this).prev().remove(); });
http://jsfiddle.net/b6vLL37k/1
source share