Jose Gallo Jose Gallo - 2 months ago 9
HTML Question

I can't delete pure text using Jquery

I have error message on the page that I want to delete using Jquery while the error is getting fixed.

I can delete all the

b
tags but I have some elements that are only pure text and I can't figure it out.

Any help, will be appreciate

This is the html:

<body class = "body.home.page.page-id-273">
<br>
<b>Notice</b>
": Undefined variable: output in "
<b>/var/www/vhost/adelapereira.com/home/html/wp-content/themes/optimizePressTheme/lib/assets/default.php</b>
</b>
" on line "
<b>2589</b>
<br>
...


And this is the Jquery I delete all the text inside the b tags, but not the pure text:

<script>
$(document).ready(function() {
$("b, b:nth-child(2), b:nth-child(3), b:nth-child(4)").css( "display", "none" );
});
</script>


Many thanks

Answer

Try this if you have no other text nodes as body childs:

$('b:eq(0), b:eq(1)').remove();
var contents = $('body').contents().filter(function() {
    return this.nodeType == 3;
}).remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<b>Notice</b>
":  Undefined variable: output in "
<b>/var/www/vhost/adelapereira.com/home/html/wp-content/themes/optimizePressTheme/lib/assets/default.php</b>