I am looking to hide anything not in a <p>
within a certain <div>
- specifically anything before the first <p>
. For example:
<div id="description">
TEXT I WANT REMOVED
<p>Keep this text</p>
<p>Keep this too</p>
</div>
I am looking to hide anything not in a <p>
within a certain <div>
- specifically anything before the first <p>
. For example:
<div id="description">
TEXT I WANT REMOVED
<p>Keep this text</p>
<p>Keep this too</p>
</div>
there isn't something like a text-node-selector in css, so the only thing that comes to my mind to solve this is setting font-size: 0;
for the outer element and back to a normal value for the p
s (although this feels kind of... dirty).
One option is to use visibility - but the problem is the space occupied by the other elements may not be properly collapsed
#description {
visibility: collapse;
}
#description p{
visibility: visible;
}
Demo: Fiddle
Another solution is
$('#description').contents().filter(function(){
return this.nodeType == 3 && $.trim(this.nodeValue) != '';
}).wrap('<span />').parent().hide()
Demo: Fiddle
May be you could try jquery:
var html = $('#description p').map(function(){
return $(this)[0].outerHTML;
}).get();
$('#description').html(html);