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
https://forums.phpfreaks.com/topic/129633-solved-getting-to-validate/
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>

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.