Get contents of BODY without DOCTYPE, HTML, HEAD and BODY tags

后端 未结 7 1560
情话喂你
情话喂你 2021-02-12 17:45

What I am trying to do is include an HTML file within a PHP system (not a problem) but that HTML file also needs to be usable on its own, for various reasons, so I need to know

7条回答
  •  时光说笑
    2021-02-12 18:31

    This may be a solution. I tried it and it works fine.

    function parseHTML(string) {
          var   parser = new DOMParser
         , result = parser.parseFromString(string, "text/html");
          return result.firstChild.lastChild.firstChild;
        }

提交回复
热议问题