How to Set the Script In Action From an External js file

Hello, I’ve created a rather lengthy jQuery script into an area that will appear on multiple pages. The script works just fine when I place it inline but when I’ve created it into an external js file and reference the script with the <script type=“javascript” src=“path to file”></script> and removed the inline jQuery, the script no longer works.

I’m wondering if it is because I have many different functions actually going on with call backs and such in the script. I’m not even sure where to place the “onclick” call onto which element, if at all.

How do you make the element that you want to be acted upon to call the script into action?

Thanks for your help.

Are you adding your script tag in the <head> or before the closing </body> tag? If you’re adding it to your <head> tag move it to just before your closing </body> tag as that will ensure it waits until the DOM is ready which sounds like the issue. If you can’t do this simply wrap your file in a document ready function like the below.

$(function() {
    // Your code here
});

The right way to call a javascript is:

<script type="[B][COLOR="#008000"]text/[/COLOR][/B]javascript" src="path to file"></script>

(and inside the javascript file there are no <script> -tags, just the script-functions theirself).
Maybe this was it?

Yes I definitely placed it like that. I don’t have access to the < head > section so I had to place it right before my content begins (in an editing window in EzPublisher). I don’t have access to any < body > or <head > tag.

Isn’t there something that I need to place in the element that it works on though? i.e. <div onclick=“some script” > to make it work?

Thanks for helping an newb to JavaScript and jQuery.