我无法使用Jquery删除纯文本

时间:2016-09-11 20:48:58

标签: jquery html

在错误得到修复时,我在使用Jquery删除的页面上有错误消息。

我可以删除所有b标签,但我有一些只是纯文本的元素,我无法弄明白。

任何帮助,将不胜感激

这是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>
 ...

这是Jquery我删除了b标签内的所有文本,但不删除纯文本:

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

非常感谢

2 个答案:

答案 0 :(得分:1)

如果您没有其他文本节点作为正文子节点,请尝试此操作:

&#13;
&#13;
$('b:eq(0), b:eq(1)').remove();
var contents = $('body').contents().filter(function() {
    return this.nodeType == 3;
}).remove();
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

试试这个:

<script>
 $(document).ready(function() {
     $('b').hide();
 }); 
</script>  

修改

- 将您的HTML更改为:

<body class = "body.home.page.page-id-273">
<div class="hide_this">
<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>
</div>
...

-     在你的jQuery

<script>
 $(document).ready(function() {
     $('.content').after('<div class="hide_this">');
     $('.fancybox-wrap').before('</div>');
     $('.hide_this').hide();
 }); 
</script>