Forum Moderators: open

Message Too Old, No Replies

Another open tag validation problem

W3C validation says end tag closing an unopened tag

         

jimandy

7:24 pm on May 1, 2006 (gmt 0)

10+ Year Member



Is there a bug here? It works fine in several browsers but doesn't pass muster with W3C. This problem is really "bugging" me.

The code....
------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> none</title>
</head>
<body>
<script type="text/javascript">
document.write('<font color="red"> this is red text</font>')
</script>
</body>
</html>
-------------------
...gives this message in the W3C validator

"Error Line 9 column 59: end tag for element "FONT" which is not open.
The Validator found an end tag for the above element, but that element is not currently open.

Huh? I thought <font> was an open tag closed by </font>.

Fotiman

7:41 pm on May 1, 2006 (gmt 0)

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



The problem is that you have not correctly escaped the "/" in your JavaScript code, so the validator sees your page like this:

<script>
</font>
</script>

The fix is to propery escape the "/" like this:

document.write('<font color="red"> this is red text<\/font>')

jimandy

10:05 pm on May 1, 2006 (gmt 0)

10+ Year Member



That worked. Thanks!

Learning is a never ending process.

JohnThomasInc

10:03 am on May 2, 2006 (gmt 0)



cool thnx