Coach, Mentor, Coder

I’m Harry Bailey and I help foster tech teams and the humans who form and fuel them. My work creates better outcomes, more value, happier humans and solid autonomous teams.

My experience as a product owner, business owner, tech strategist and software developer enables me take a team-focussed approach. I look to support value creation at every level from pair coding through to business strategy.

Get in touch

Validation of html within inline javascript

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>