I'm triying to create an XHTML/transitional valid page, but I can't figure out how to remove this error: On this line: document.write("<a href=\"wherever.htm\">whatever</a>"); W3C validator underlined the first \ and said: an attribute value must be a literal unless it contains only name characters What does it mean? How to validate this line? Any help will be appreciated. TY
Should probably just be able to use single quotes in lieu of one of the sets of double quotes and you'll be fine.
Ok - it worked, but now I have document type does not allow element "a" here It's inside a <p><script> and </script></p> !!!
I use javascript for SEO reasons. here is the html <h6>Catégories:</h6> <p id="categories"> <script type="text/javascript" language="javascript"> document.write("<a href='cars-0.htm'>Cars</a>"); document.write("<a href='Jobs-0.htm'>Jobs</a>"); document.write("<a href='and-so-on-0.htm'>and so on</a>"); </script> </p> Code (markup):
According to W3, all you need to do regarding atributes with XHTML, is quote them AKA put them in quotes. So regarding the original section of code: document.write("<a href=\"wherever.htm\">whatever</a>"); <a href=\"wherever.htm\">whatever</a> Code (markup): So in the actual XHTML code part of the code... all you need to do is include the first \ in the quotes to make it XHTML compatible, however you probably shouldn't need to use a \ anyway... Ok hopefully that helped, if it didn't and if I've just gone off on a tangent just ignore me or slap me Diarmuid
Finally I remember. It was so obvious :<!-- and //--> The W3C Xhtml validation bot cannot read Javascript, thus, I have to tell him to escape it. of course!!!
You need to wrap it in CDATA. <script type="text/javascript" language="javascript"> <![CDATA[ document.write("<a href='cars-0.htm'>Cars</a>"); document.write("<a href='Jobs-0.htm'>Jobs</a>"); document.write("<a href='and-so-on-0.htm'>and so on</a>"); ]]> </script> Code (markup):