I was wondering how to remove empty elements, but allow only one empty element per group (next to non-empty one) ?
Something like :
Example HTML :
<p>Hello world</p>
<p><br></p>
<p><br></p> <!--This will remove-->
<p><br></p> <!--This will remove-->
<p>Lorem ipsum dolor sit amet</p>
<p><br></p>
<p><br></p> <!--This will remove-->
<p>Eum ne nostro admodum</p>
<p><br></p>
And jQuery for checking the empty elements :
var p_empty = $('p').filter(function(i,v){return $.trim($(v).text()).length===0;});
Now I got all empty elements, But any idea how to remove those next empty elements ?
Workflow : http://jsfiddle.net/jmy0uzw1/
PS: I am looking for good JS performance also
In your case since you are not using containers, you will have to use sibling selectors
+
and make sure the precedingp
element itself is not of.empty