Hacker News new | ask | show | jobs
by dbaupp 4105 days ago
document.write is pretty wild, as it can modify the HTML token stream directly, e.g.

  <html>
    <script>
    document.write("<h");
    </script>1>
    This is a h1 title
    <script>
    document.write("<!-");
    </script>-
    This is commented
    -->
  </html>
(From http://www.reddit.com/r/rust/comments/2zir9s/html5ever_proje... )
1 comments

What?! Why. why. why would anyone ever need this, and why would it ever be made available? I'm just completely dumbfounded by this.
Apparently a lot of the older webpages do stuff like this. You could have a table being outputted by nesting for loops for the `<table>`, `<tr>`, and `<td>` opening/closing tags. It's a small step from here to constructing tags bit by bit.

I don't see people doing it in modern websites (doesn't mean there aren't), but we sort of have to support all of the Internet, so...