I’ve got something like this:
jQuery(this_element).replaceWith('<div>' + jQuery(this_element).html() + '</div>');
It works fine but after execution this_element still contains old element (that doesn’t exist anymore because it has been replaced with <div>old content</div>). How can I restore selection in that element or at least grab new element to this_element variable?
Create the new object separately, then keep a reference to that (jQuery 1.4+):
(This uses the
jQuery(html, props)method.)jsFiddle