Keith Power
Keith Power

Reputation: 14151

w3c validation of <a> inside javascript

I have some javascript to set makers for google maps. Inside the markers I have links <a>link</a> to display on the map.

Howver the W3C valdiator complains about the > at the end of the opening <a>. I have tried replacing it with &gt; but it complained about the &.

Is there a way around this?

Thanks

["<a href='/thebrianboru'>The Brian Boru</a>&lt;br />5 Prospect R…

Upvotes: 3

Views: 107

Answers (4)

Subhojit Mukherjee
Subhojit Mukherjee

Reputation: 719

You can use any of them below:

<script type="text/javascript">
<!--
YOUR JS CODE .........
alert("www.mykitchenroom.com");
// -->
</script>

OR,

<script type="text/javascript">
//<![CDATA[
YOUR JS CODE .........
alert("www.scienceanddevelops.com");
//]]>
</script>

W3C will don't check your code.

Thanks And Regards, Subhojit Mukherjee

Upvotes: 0

jbabey
jbabey

Reputation: 46657

If this is inside of a <script></script> block in HTML, it could cause problems:

The script should not contain the sequence

</ because it could be confused with the </script>. Inserting a backslash between < and / in strings avoids the problem.

<\/

http://javascript.crockford.com/script.html

Upvotes: 0

Niko
Niko

Reputation: 26730

Sounds like XHTML? Put the JavaScript in a CDATA section: http://en.wikipedia.org/wiki/CDATA to tell the interpreter, that it should ignore special characters like < > and &.

<script>
<![CDATA[
    // ...
]]>
</script>

Upvotes: 0

Paul
Paul

Reputation: 141935

Seems like you're using XHTML. Wrap your code in a commented out CDATA:

<script type="text/javascript">
//<![CDATA[

// Now I won't complain :)
var x = '<7>%></a>#$#><>><&&>';

//]]>
</script>

Upvotes: 3

Related Questions