Thursday, 15 November 2018

How to change the image source using Javascript.

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('newrose');
    if (image.src.match("close")) {
        image.src = "roseopen.jpg";
    } else {
        image.src = "roseclose.jpg";
    }
}
</script>
</head>
<body>
<center><H1>Open/Close the Rose Bud  by just one click.</H1>
<img id="newrose" onclick="changeSRC()" src="roseclose.jpg" width="180" height="180">




</center>
</body>
</html>


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

Java Unit Wise Notes

 JAVA Notes   --- UNIT-I DETAILED NOTES (JAVA) 1. History of Java Developed by James Gosling at Sun Microsystems (1991–1995). Initia...