0

Can I somehow load a "broken" DOM tree in JavaScript

for example if someone forget to close a tag..

  • Presuming you want to do this within a browser environment, see http://stackoverflow.com/questions/494143/how-do-i-create-a-new-dom-element-from-an-html-string-using-built-in-dom-methods and http://stackoverflow.com/questions/888875/how-to-parse-html-from-javascript-in-firefox and http://stackoverflow.com/questions/2522422/converting-a-javascript-string-to-a-html-object/2522467#2522467 – Crescent Fresh Aug 11 '10 at 11:21

1 Answers1

0

The current page? ...if this is an HTML document (ie. not served as XHTML) then the browser will auto-close (and even attempt to 'fix') certain elements that may at first appear 'broken'. When reading the current DOM, you are reading the fixed version. However, if the page is in fact 'broken' (or is just not standards compliant) then different browsers will 'fix' it differently. Depending on how broken is "broken", this may or may not be OK. If you are wanting this to work cross-browser, then this is probably not OK.

MrWhite
  • 43,179
  • 8
  • 60
  • 84