删除 HTML 页面中不在元素标签内的文本 [英] Remove text in HTML page not inside element tag

查看:19
本文介绍了删除 HTML 页面中不在元素标签内的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常新手的问题,但不确定如何实现这一点.有一个html页面显示如下

This is probably a very novice question but not sure how one could achieve this. There is an html page that shows as follows

<html>
   <body>
      <div><p>Hello!</p></div>
      <"
   </body>
</html>

我的问题是,有没有办法通过javascript或css删除或着色html元素之外的<"?

My question is, is there a way to either remove or color the <" which is outside an html element via javascript or css?

推荐答案

您可以使用 Jquery 做到这一点:

You can do it with Jquery using this:

$('body').contents().filter(function(){ return this.nodeType != 1; }).remove();

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<html>
 <div><p>Hello!</p></div>
 
 <"

</html>

这篇关于删除 HTML 页面中不在元素标签内的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆