We Can just recall the previous example of image switching to understand how to call script externally.
Let's have a look.
functions.js:
Let's have a look.
<html> <head> </head> <body>Using the tagclick on the image
</body> </html>
<script type="text/javascript" src="functions.js"> </script>we can call the script externally. Always write script in file with extension ".js".
functions.js:
function imageswitch(){
var image = document.getElementById('switchimage');
if(image.src.match("one"))
{
image.src = "flower_two.jpg";
}
else
{
image.src = "flower_one.jpg";
}
}
Note:
Make sure that the both html and js file locations are the same or else defime them specifically
</body>
</html>
Comments
Post a Comment