Ajax functions such as .load () extract comments from HTML. How can I store comments?

For example, $('#some-div').load('http://foo.bar #content') will retrieve #content from http://foo.bar , but all the HTML <!--comments--> deprived.

How can I get the contents of #content , including any comments?

+4
source share
1 answer

From the jQuery manual:

jQuery uses the browser .innerHTML property to parse the extracted document and paste it into the current document. During this process, browsers often filter elements from the document, such as <html> , <title> or <head> elements. As a result, the elements obtained using .load() may not be as if the document were received directly by the browser.

Therefore, you should use $.get() to extract the HTML instead of $.fn.load()

+1
source

Source: https://habr.com/ru/post/1342792/


All Articles