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

CSS and type of CSS

1. Inline CSS (The "Direct Note")This is written directly inside the HTML tag.  It’s like putting a sticker right on an object.B...