0

In WordPress I am using this code in my functions echo "<script type=\"text/javascript\"> which causes this XHTML validator error: "an attribute value must be a literal unless it contains only name characters"

I need this to be in my functions in WordPress, but also to be XHTML valid. I don't know much about any kind of coding, I'm a CSS and HTML junkie. Any help/

EDIT: REST OF THIS SECTION OF CODE:

if ($toggle == "no"){
echo '<link rel="stylesheet" href="'.get_template_directory_uri().'/tagmap.css" type="text/css" media="screen" />';
echo "\n\n";
echo "<script type=\"text/javascript\">
jQuery(document).ready(function() { 
  jQuery('ul.links li.hideli').hide();
  jQuery('ul.links li.morelink').show();
  jQuery('a.more').click(function() {
    jQuery(this).parent().siblings('li.hideli').slideToggle('fast');
     jQuery(this).parent('li.morelink').remove();
  });
});
</script>\n\n";
7
  • What you have does not look wrong. Maybe something in the context is causing the error. You can try single quotes around the value of the type attribute: <script type='text/javascript'> just in case. Commented Sep 22, 2011 at 0:10
  • Are you missing the end quote? Or is that just a copy/paste error? Commented Sep 22, 2011 at 0:13
  • @Ray Toal - That is invalid xHTML. I'd rather do this: echo '<script type="text/javascript">';. Commented Sep 22, 2011 at 0:17
  • I'm not sure what's wrong... I just edited my post to show more of the code. I really appreciate any help. Commented Sep 22, 2011 at 0:17
  • The validation service should show you the exact character where this fails (Line #: Column #:)... please look at that and tell us what it says. As noted above it is probably something with string escaping and you should change your quoting style. Commented Sep 22, 2011 at 0:39

1 Answer 1

1

You are trying to validate <script type=\"text/javascript\">, which is invalid... the validation service highlights the slash character for you at column 14. You cannot have a slash character before the open quote starts in type=.

Update

Check the HTML source of your page which is what the validator is actually checking... line 21 Column 14 is where your Google Analytics code starts, not the jQuery code.

Line 20: <!-- Google Analytics -->
Line 21: <script type=\"text/javascript\">

You need to remove the slashes here.

Sign up to request clarification or add additional context in comments.

2 Comments

It is still returning a validation error... or are my cookies really messed up in my browser? :-S validator.w3.org/…
Look at the generated HTML source code... line 21 is where your Google Analytics code starts, not where your jQuery code is. You need to change the quotes there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.