Vika Vika - 7 months ago 26
jQuery Question

Jquery unwrap in each

I have a problem with my unwrap, here is my HTML code :

<div id="MyDiv">
<span class="highlight" id="highlight_36">bolo</span>
<span class="highlight" id="highlight_37">lapso</span>
bla bla bla bla

If i execute :

$(".highlight").each(function() {
// complicated operation


After my each, (in my browser inspector) HTML code becomes :

<div id="MyDiv">
bla bla bla bla

How to obtain this HTML code ?

<div id="MyDiv">bolo caret lapso bla bla bla bla</div>


I don't see why you need this, but if you really need to, you can use this after your operation:

var el = document.getElementById('MyDiv');
el.innerHTML = el.innerHTML.replace(/(\s|\r|\n)+/g, ' ').trim();

That will replace every doublespaces, linebreaks and tabulations from you string and reasign it the the element.