Forum Bugs

Javascript - <h2> in Comment?

jimbrooking
I have been working on generating a ToC using the code in this post by StoneCypher:
http://www.princexml.com/forum/topic/1899/here-have-an-automatic-toc-script
I had a line of HTML that went something like
<h2 id='h2_10'>something</h2>

But I wanted not to display the "something" between the <h2> and </h2> so in the function "init" from StoneCypher, after the ToC has been generated and inserted in the <div> I wanted it in, I put a line of JavaScript:
document.getElementById('h2_10').innerHTML='';    // clear something from <h2> for that section

(including the comment)

Well, Prince 10 wouldn't parse and convert the file complaining about the h2 not having proper closure. After staring at the code until my eyes hurt it occurred to me that maybe it was thinking the comment needed a closure. So I changed the line to read
document.getElementById('h2_10').innerHTML='';    // clear something from h2 for that section

(removing the <>'s) and it converted perfectly.

This sort of feels like a bug, and I wanted you to know about it.

Thanks for Prince and your outstanding support.

Jim
mikeday
In XML, <script> elements get no special treatment, so less-than characters need to be escaped. In HTML, <script> elements are treated specially up until the closing </script> tag, and less-than characters can be used without escaping.

It is subtle differences like this that drive people crazy, but what can we do. :D
jimbrooking
Thanks, and sorry to bother you.