Program to change the image source using Javascript.
(2 minutes coding)
Steps to make your own image source changing program
1. Open NOTEPAD or NOTEPAD++ in your computer .
2. Copy the code given below .
<html>
<head>
<script>
function changeSRC() {
var image = document.getElementById('newbulb');
if (image.src.match("off")) {
image.src = "onbulb.jpg";
} else {
image.src = "offbulb.jpg";
}
}
</script>
</head>
<body>
<center><H1>Turn the Bulb ON/OFF by just one click.</H1>
<img id="newbulb" onclick="changeSRC()" src="offbulb.jpg" width="100" height="180">
</center>
</body>
3. Now paste it in your Notepad file.
3. Now save your file with .html extension.
4. File will appear like this.
5. Now open the file in any browser.
6.Click on the rose image to change the image source.
No comments:
Post a Comment