Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

W3C validation issue

Featured Replies

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:

post-4145-125131061964_thumb.gif

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.

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[

 

...

 

//]]>

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.)

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.

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.