/    Sign up×
Community /Pin to ProfileBookmark

dhtml, html, or javascript??

Hey

i building my own website and am just curious about something. when someone clicks on an image(“image1.gif”) i want the image to change into a different image(“image2.gif”)
how do i get this function to work properly??

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@AdamGundryFeb 12.2003 — Try this (though you might want to preload image2.gif):

<img src="image1.gif" onclick="this.src = 'image2.gif'">


Adam
Copy linkTweet thisAlerts:
@gmichalMar 07.2003 — what the syntax for the preload img? i know u need to write it on the body tag

<body onload="?????">
Copy linkTweet thisAlerts:
@AdamGundryMar 09.2003 — Use something like this:
[CODE]
<body onload="preloadImages()">

<script type="text/javascript">
var i = new Image();
i.src = 'image2.gif';
</script>
[/CODE]


This creates a new image object and assigns it at source of image2.gif, so when the browser finishes loading (the onLoad event is called) the image will be preloaded for the change.

Adam
×

Success!

Help @dennic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...