|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Hi, i have a *.js file containing all the fuctions i need that build a menu.
In my page i have an image which i want to add on to it an on MouseEvent let's say onClick and when this image is clicked to bring the javascript file! is this done?? i knwow it is done when i have a single Javascript function but what happens when i have a javscript file full of functions?? thank u!! |
|
#2
|
||||
|
||||
|
You can't combine the image and javascript files themselves...
However you can include the *.js file in the HEAD of your page and call a method in the JS file from the onclick attribute of the IMG tag. Code:
<html>
<head>
<script type="text/javascript" src="whatever.js"></script>
</head>
<body>
<img src="whatever.jpg" onclick="javascript:someMethod();">
</body>
</html>
|
|
#3
|
|||
|
|||
|
where will the method be declared??
thank u for your help, its understandable but where am i suppose to declare the method??
is it on the head section and including inside it the javascript link?? please can u make that more clear?? thank u |
|
#4
|
||||
|
||||
|
In reference to my brief code example above, you could put your entire method in the whatever.js file.
You don't need to use a js file at all, you could embed all of your javascript code in the HEAD (within SCRIPT tags) if you want to, but it might be better as a seperate file. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > call javascript file from an image |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|