Search code examples
javascriptvalidationxhtml-1.0-strict

Is there a valid way to include my <span> element within the following JavaScript?


I have this simple little JavaScript snippet to try and protect my email address a little:

<p>Email:<br />
<script type="text/javascript">
    mixupE='mywebsite.com'
    mixupE=('myname' + '<span>@</span>' + mixupE)
    document.write(mixupE)
</script>
</p>

The problem is that it is the only section of code that doesn't validate a xhtml strict. It's to do with the span @ /span part. I have just include the span so that I can style the @ symbol different to the rest of the email address.

Anyone got any better ways of doing this?

Ideally I'd like to get everything to validate :o)

I've solved it by just doing this at the moment:

<p>Email:<br />
        <script type="text/javascript">
            mixupA='name'
            mixupA=('my' + mixupA)
            document.write(mixupA)
        </script><span>@</span><script type="text/javascript">
            mixupB='site.com'
            mixupB=('myweb' + mixupB)
            document.write(mixupB)
        </script>
</p>

Probably not the best way of doing things, but it seems to work and my pages now validate as xhtml strict :o)


Solution

  • Use an indirect way of representing <:

    <script type="text/javascript">
      var lt = String.fromCharCode(60);
      mixupE='mywebsite.com'
      mixupE=('myname' + lt + 'span>@' + lt + '/span>' + mixupE)
      document.write(mixupE)
    </script>