PDA

View Full Version : "Simple" validation error


harbingerOTV
01-14-2009, 01:08 AM
okay this is dumb and please don't ask why I'm using document.write ;)

<script type="text/javascript">
document.write('<a href="#x" class="backtotop">Top of Page</a>');
</script>

I'm using that on a site but of course the validator says this:


line 194 column 60 - Warning: '<' + '/' + letter not allowed here


If I remove the "/" and use "/" it prints out "</a>" at the end of the link although the script still functions correctly.

Besides not using document.write, how do I go about remedying this situation?

I'm working on a way to use jQuery to make adjustments but in the meantime...

_Aerospace_Eng_
01-14-2009, 05:56 AM
You could use CDATA comments which I think might be a better solution.

http://javascript.about.com/library/blxhtml.htm

Or you could try escaping that character.
<script type="text/javascript">
document.write('<a href="#x" class="backtotop">Top of Page<\/a>');
</script>

harbingerOTV
01-14-2009, 03:11 PM
"escaping", of course! Told you it was simple I just couldn't, or rather didn't want to think that easy. gracias.