-1
Using some Javascript method, how could you remove elements that are soiling HTML?
I have the following HTML:
<div class="container-text">
<p> Teste onon onon noonnoon </p>
<p> Teste onon onon noonnoon </p>
<p> </p>
<figure><img src="/path/img/teste.jpg"></figure>
<p> </p>
<p> Teste onon onon noonnoon </p>
</div>
How could I remove the empty paragraph that is before after <figure> (siblings / brothers)?
I tried so:
function removeParagraphAfterAndBeforeFigure(result) {
var el = document.createElement('div');
el.innerHTML = result;
el.querySelectorAll('figure')
.forEach(function(figure){
figure.parentNode.querySelectorAll('p').forEach(function(p){
if(p.textContent == '' || p.textContent == ' ') {
p.parentNode.removeChild(p);
}
});
})
result = el.innerHTML;
return result;
}
If your tag looks like this
<p></p>, without the space inside, type a tag pasted right into the other, you can use the pseudo class:emptyCSS to give a None display in that paragraph– hugocsl
Do you have to be the direct brother of the figure? If you have one
pempty at first, should it stay? Or have to clear any empty paragraph inside thediv, no matter where he is?– Cmte Cardeal