0

I have looked around for similar questions and I couldn't find an answer...

I'd like for one particular page of my web site to import a file ("clock.js"):

<script type="text/javascript" src="clock.js"></script> 

and, on load, to run the function tick() from that page.. in the body of the document.

I know I am supposed to do it this way:

$(document).ready(tick); 

But it doesn't work and I suspect it's because these lines of code are in the middle of the document.

Any suggestions?

7
  • It's in the body of my document (I'm importing the head and foot of my website templates, hence why I'm doing this mid-document). Commented Nov 22, 2011 at 20:10
  • What is going wrong? Is the tick() function not called at all? where you put the .read(), shouldn't matter. It will be execute after the document is ready Commented Nov 22, 2011 at 20:10
  • 5
    That should work anywhere. Do you get an script errors in Firebug? Commented Nov 22, 2011 at 20:10
  • @JDelonge: By importing, do you mean including? And if so, by "head" do you mean the <head> tag? Commented Nov 22, 2011 at 20:14
  • @SLaks: I assume not before downloading jQuery Commented Nov 22, 2011 at 20:15

1 Answer 1

2

apparently the code should work. you can try

jQuery.getScript("clock.js",function(){ tick(); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.