Does jQuery strip some html elements from a string when using .html()?

后端 未结 4 1515
遥遥无期
遥遥无期 2020-12-01 18:20

I have a var that contains a full html page, including the head, html, body, etc. When I pass that string into the .html() function, jQuery strips out all those elements, s

4条回答
  •  日久生厌
    2020-12-01 18:53

    Nope, the jQuery html function is just sending the string through to the element's innerHTML property, which is a function of the browser that tells it to parse the HTML into DOM elements and add them to the page.

    Your browser doesn't work with a page as HTML data, it works with it as DOM and imports/exports HTML.

    JavaScript has very good Regular Expression support. Depending on the complexity of your task, you may find this is the best way to process your data.

提交回复
热议问题