4

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

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

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
trusktr
  • 44,284
  • 53
  • 191
  • 263

1 Answers1

1

From the jQuery manual:

jQuery uses the browser's .innerHTML property to parse the retrieved document and insert 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 retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

So you should use $.get() to retrieve the HTML instead of $.fn.load()

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
CarlosZ
  • 8,281
  • 1
  • 21
  • 16
  • Part of your answer was filtered out. If you put a space after "<" i'll understand. Can you add those parts? Anyways, according to the jQuery API reference, .get() is called like this: `.get( [ index ] )`... There is no ability implemented with it to grab contents from other locations (URLs). – trusktr Mar 08 '11 at 23:38
  • The $.get() I'm referring to is http://api.jquery.com/jQuery.get As for the format of the answer it looks good to me. The last line is of my own not from JQuery's doc. – CarlosZ Mar 08 '11 at 23:43
  • Oh cool. I'm taking your word for it. ;) I'll try it out soon. :) – trusktr Mar 15 '11 at 23:59