Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>YAY. I figured it out. Hopefully nobody was working on this and I didn't waste anyones time. I'm posting it here so if anyone else has this problem in future...</p> <p>I checked out the draft view to see the source of jsfiddle (should of thought of this before asking). And it was showing this as the javascript --></p> <pre><code>&lt;script type='text/javascript'&gt;//&lt;![CDATA[ $(window).load(function(){ colors = ['red', 'blue', 'green', 'gray', 'black', 'yellow']; $(".test a").hover(function() { randomColor = Math.floor(Math.random() * colors.length - 1) $(this).css('color', colors[randomColor]) }, function() { $(this).css('color', '#000000') }); });//]]&gt; &lt;/script&gt; </code></pre> <p>So I decided to leaver randomcolor as a separate file, and to get it to work I put the CDATA like so --></p> <pre><code>&lt;script type="text/javascript" src="randomcolor.js"&gt;&lt;![CDATA[//]]&gt;&lt;/script&gt; </code></pre> <p>SO....if anyone else is trying to get a code like this working (random color, link hover), here is the final code that worked for me (different than the actual document I'm using it in).</p> <p>HTML</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=utf-8 /&gt; &lt;title&gt;JS Bin&lt;/title&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="randomcolor.js"&gt;&lt;![CDATA[//]]&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="test"&gt;&lt;a href="http://test.com"&gt;Please work&lt;/a&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>JS</p> <pre><code>$(window).load(function(){ colors = ['red', 'blue', 'green', 'gray', 'black', 'yellow']; $(".test a").hover(function() { randomColor = Math.floor(Math.random() * colors.length - 1) $(this).css('color', colors[randomColor]) }, function() { $(this).css('color', '#000000') }); }); </code></pre> <p>I hope this helps someone else!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload