I have a site hosted by GitHub that uses Jekyll, and I (successfully) used an internally defined script in each layout that would generate a random label from an array of them.
I am trying to move this script to an external one tagline.js, but so far I have not been successful.
Here's the main tagline creating the script, in the event of something in the code causing it (which, to be honest, I doubt its simplicity, but it is always possible):
var tags = ['tag1', 'tag2', 'tag3'];
function getTag() {
return tags[Math.floor(Math.random() * tags.length)];
}
$(document).ready(function() {
$("#tagline").text(getTag());
});
As I said, it works great when it is internal, but does not work when I try to connect to the external. I am sure this is just the case when I indicate <script>: the HTML file containing <script>is in _layouts/default.html, but the script is in scripts/tagline.js.
EDIT: Sorry, I used " <link>" when I meant " <script>". Thus, this fixes the “you're using the wrong tag” solution !: P
EDIT2: full <script>(again, located in the HTML file at _layouts/default.html):<script type="text/javascript" href="../scripts/tagline.js"></script>
source
share