Forum Moderators: open

Message Too Old, No Replies

Validating html written with document.write

         

stef25

5:28 pm on Apr 26, 2006 (gmt 0)

10+ Year Member



I have a few lines of html that are written to the document using document.write:

document.write('<a href="product1.html" onmouseover="mouseOver(\'pans\',\'pans_hov\')"><img src="images/rollovers/pans.gif"/></a>')

When i try to validate this, W3 reports end tag for element "A" which is not open, referring to the closing A tag

when i replace that with &lt; and &gt;, it shows as </a> on my html page

Is this a catch 22 impossible to get around?

encyclo

5:34 pm on Apr 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The markup is valid, just that it doesn't validate. :) Its not reall a catch-22 as it is more to do with how the validator functions than an actual problem with the page.

You can either use standard HTML comments around the inline Javascript or place the JS is a separate file if you really want to get rid of the "error", otherwise just leave it as it is.

stef25

5:42 pm on Apr 26, 2006 (gmt 0)

10+ Year Member



thanks for your prompt reply

what do you mean with html comments: /**/?

can you give an example?

Fotiman

6:22 pm on Apr 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You should be escaping the slashes, like you did with the single quotes:

document.write('<a href="product1.html" onmouseover="mouseOver(\'pans\',\'pans_hov\')"><img src="images\/rollovers\/pans.gif"\/><\/a>')