...

View Full Version : HTML in JS wont validate



Bobafart
02-28-2008, 06:37 PM
the HTML validator wont validate this:

document.getElementById('newsDisplayClassic').innerHTML = '<img src="http://www.foo.com/img/icons/icon_newsDisplayCheckmark.png" width="32" height="26" alt="" />';

how do I write it so it is valid?

oesxyl
02-28-2008, 06:46 PM
the HTML validator wont validate this:

document.getElementById('newsDisplayClassic').innerHTML = '<img src="http://www.foo.com/img/icons/icon_newsDisplayCheckmark.png" width="32" height="26" alt="" />';

how do I write it so it is valid?

you must use CDATA section in xhtml strict to insert chars as <, & , >
as in this example:



<script type="text/javascript">
// <![CDATA[
your js code
// ]]>
</script>


also you can use the html comments instead, <!--, -->

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum