Jump to content

[SOLVED] Getting <script> to validate???


amin7b5

Recommended Posts

I'm really struggling to get a piece of script to validate in xhtml 1.0. The code is the following:

 

<script type="text/javascript">window.addEvent('domready', function() { new YOOtooltip('yoo-tooltip-1', '<img src="images/latest_work/aos.jpg" alt="Alt Text" /><p>Text goes here</p>', { mode: 'cursor', display: 'block', width: 315, style: 'default', sticky: 0 }); });</script>

 

This doesn't validate because of the html code within the script tag, however if I replace the '<' and '>' with < and > it will validate but break the script!

 

My javascript knowledge is limited and this is a third party tool tip script. Thanks in advance for any advice on how to get this to validate!

Link to comment
Share on other sites

Add <!-- and --> around the code inside the script.

 

<script type="text/javascript"><!--window.addEvent('domready', function() { new YOOtooltip('yoo-tooltip-1', '<img src="images/latest_work/aos.jpg" alt="Alt Text" /><p>Text goes here</p>', { mode: 'cursor', display: 'block', width: 315, style: 'default', sticky: 0 }); });--></script>

Link to comment
Share on other sites

Just to let you know, this is quite customary for Javascript code to use in order to prevent older browsers that don't understand Javascript (I'm talking REALLY old browsers) from just outputting all of the JS.  Oh, and by the way, since that fixed it, you should really use:

 

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

 

That's the right way to do it, I just wanted to see if commenting would fix your problem.

Link to comment
Share on other sites

When I change the comments to <![CDATA[ as recommended, the script breaks. From what I've been reading, this may be due to the fact that the page is serving in text/html and <![CDATA[ will only work if it's serving in application/xhtml+xml.

 

I'm unsure how to change this. ???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.