If you are finding you need to use javascript inside an html or xhtml file and it won’t validate, then here is a little tip for you.
If you surround all your javascript with <![CDATA[ and ]]> tags, all will come good.
The CDATA is seen by the validator as data which doesn’t need checking. So this:
<script> document.getElementById('container').innerHTML('<p>hello</p>'); </script>
becomes this:
<script> <![CDATA[ document.getElementById('container').innerHTML('<p>hello</p>'); ]]> </script>
Another option is to escape < and > characters server-side / in the file and then unescape with javascript
<script> document.getElementById('container').innerHTML('<p>hello</p>'.replace('/</','<').replace('/>/','>')); </script>