0

I am having trouble calling a Javascript file to be executed. Here is the Javascript reference link to the file:

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

Now the problem that I am having is that I want to have a certain link activate the script upon clicking a link.

<a href="#" onClick=""><img src="myimage.png" /></a>

Because the script for the file is actually external, I guess my primary question is how would I go about executing an external script using either Javascript or jQuery? I'm really lost right now, so all help is greatly appreciated!

2
  • function addScript(url,d){ d=dcoument; d.getElementsByTagName('script')[0].parentNode.appendChild(d.createElement('script')).src=url; } Commented Oct 29, 2013 at 21:03
  • does snow.js execute immediately upon loading or does it contain a function you need to call? Commented Oct 29, 2013 at 21:17

2 Answers 2

1

You can just do

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="snow.js"></script>
</head>
<body>
    <a href="#" onclick="snow.js"><img src="myimage.png" /></a>
</body>
</html>

And then, in file snow.js, you put whatever javascript you want to be executed.

Sign up to request clarification or add additional context in comments.

Comments

0

step 1: put every thing in the javascript function in side a function

function myFunction()
{
// all the code in the script file
}

step 2 : call this function on click event

<a href="#" onclick="myFunction()"><img src="myimage.png" /></a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.