|
#1
|
|||
|
|||
|
Hi, i don't know if this is the correct place for this but here goes.
I have an image inside an <a> tag and need it to change when clicked. Most of the examples i've seen will change once clicked but don't change back to the original image when clicked again. I don't suppose any of you Javascript guru's could knock something up that will do this? Any help would be appreciated. Thanks, Andrew |
|
#2
|
|||
|
|||
|
i don't know JS well enough to ramble something off the top of my head, but it seems pretty straight forward if you have code to change it when clicked. just keep track with a variable (if it's only 2 images, it could even be a boolean) and hack the code to change the desired image based on what the current value of the variable is.
something like image = ((image == 1)?0:1); then display 'image'+image to show either image1 or image0 there may be a more eloquent way to do it, but that's usually how i do these sorts of things. |
|
#3
|
|||
|
|||
|
Not much Javascript here either.
do an onmouseout= ?????? function mouseOut() { document.b1.src ="imagename.jpg .gif whatever"; } and add this within your <a> tag onmouseout="mouseOut()"> Last edited by atlan; 06-11-2008 at 01:28 PM. |
|
#4
|
||||
|
||||
|
In the header, try:
Code:
var img1 = image1.jpg;
var img2 = image2.jpg;
var imageChoice = 1;
function imageChange(element) {
if (imageChoice == 1) {
element.src == img2;
imageChoice = 2;
}
else if (imageChoice == 2) {
element.src == img1;
imageChoice = 1;
}
Code:
<img src="image1.jpg" onclick="imageChange(this);">
__________________
Follow me on Twitter! http://twitter.com/mrw |
|
#5
|
|||
|
|||
|
combined with my code, it'd be a bit cleaner. at the least, that shouldn't an else if as it'll make the second if be evaluated which is unnecessary. else should be enough alone.
|
|
#6
|
||||
|
||||
|
I like to do it because it makes it easier for me to follow with my own code, and if it doesn't work, it could mean something else is wrong.
__________________
Follow me on Twitter! http://twitter.com/mrw |
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Javascript Popup | esl | Webhosting | 10 | 10-03-2007 06:31 PM |
| Javascript Form Help | tomowa | Off-Topic | 2 | 03-15-2007 11:26 AM |
| Javascript suggestions | britbob | Web Hosting Services | 0 | 03-15-2005 10:18 PM |
| javascript and other extensions | Anonymous | Pre-Sales Questions | 1 | 07-08-2004 01:15 AM |
All times are GMT -5. The time now is 09:54 AM.










