Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72416

change image when clicked in using javascript

$
0
0

I have two images and i want to show them one by one when clicked in it in same position.

some codes that i tried:

<img id ="imageOne"
src="eye-solid.svg"
alt=""
style="width: 10%; height: 10%; float: right;"
onclick="changeImg()">

similarly, javascript i used;

var image =  document.getElementById("imageOne");

        function changeImg()
        {
            if (image.getAttribute('src') == "eye-solid.svg")
            {
                image.src = "key.png";
            }
            else
            {
                image.src = "eye-solid.svg";
            }
        }

and i don't want it in jQuery,


Viewing all articles
Browse latest Browse all 72416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>