August 26, 200917 yr Hi all, Does anyone know why the W3C validator would throw a wobbly about this: //Loop through all tags for (i = 0; i < all_html_tags.length; i++) (bearing in mind it's in between script tags) Here's an image of the error:
August 26, 200917 yr Hi Are you commenting out the JavaScript code with a CDATA section? I quote from a tutorial: "Use of character data (CDATA) section: a refinement on the comment notation for hiding script. Used for shielding JavaScript code that contains special characters such as <, >, & and " from the browser without the need to use character or numeric entity reference values. " See: http://www.justfigures.co.uk/javascriptbasicsplus/javascriptbasicsplussnippets1.php for code. That is what it might be. I assume the JavaScript works and you just what it to pass W3C validation.
August 26, 200917 yr Hi again I have decided to put the code here for easy viewing. Example: <script language="JavaScript" type="text/javascript"> //<![CDATA[ var booleanTest2; booleanTest2=(4<2); document.write("The condition (4<2) is " + booleanTest2.valueOf()); document.write("<br />"); //]]> </script> The CDATA section is of course the //<![CDATA[ ... //]]>
August 26, 200917 yr Hi again Yes the code as is in the example above does pass the W3C validation for XHTML 1.0 Transitional. The actual address of the page that contains the example code above is: http://www.justfigures.co.uk/javascriptbasicsplus/1_booleanTestA.html If you want to check it. That all.
August 26, 200917 yr If you put all your JS in separate files you don't have to worry about this. (And it's recommended to separate behaviour (JS) and layout (CSS) from the content (HTML) anyway.)
August 26, 200917 yr If you put all your JS in separate files you don't have to worry about this. (And it's recommended to separate behaviour (JS) and layout (CSS) from the content (HTML) anyway.) Yes of course what you say is correct and a far better solution. But scaz182 said he had the code between script tags.
August 26, 200917 yr Author Hi Are you commenting out the JavaScript code with a CDATA section? I quote from a tutorial: "Use of character data (CDATA) section: a refinement on the comment notation for hiding script. Used for shielding JavaScript code that contains special characters such as <, >, & and " from the browser without the need to use character or numeric entity reference values. " See: http://www.justfigures.co.uk/javascriptbasicsplus/javascriptbasicsplussnippets1.php for code. That is what it might be. I assume the JavaScript works and you just what it to pass W3C validation. Okay thanks justfigures, its amazing how I was so unaware of this! EDIT: just checked the link you gave me and noticed it was your site, that'll have to be bookmarked! If you put all your JS in separate files you don't have to worry about this. (And it's recommended to separate behaviour (JS) and layout (CSS) from the content (HTML) anyway.) I would but it's such a short function that adding it a seperate file doesnt seem worth it!
Create an account or sign in to comment