Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

change image onclick javascript

//in html
<img id="img" data-image="user1" src="/assets/user1.jpg" onclick="change_image()" />

//in javascript
const img = document.getElementById('img');
const change_image = function() {
  if (img.dataset.image == "user1") {
  	img.src = "/assets/user2.jpg";
    img.dataset.image = "user2";
    return
  };
  
  if (img.dataset.image == "user2") {
  	img.src = "/assets/user1.jpg";
    img.dataset.image = "user1";
    return
  };
};
Comment

js click Change img

function imagefun() {
            var Image_Id = document.getElementById('getImage');
            if (Image_Id.src.match("imageName1.jpg")) {
                Image_Id.src = "imageName2.jpg";
                Image_Id.src = "imageName3.jpg";
            }
            else {
                Image_Id.src = "imageName1.jpg";
            }
        }
Comment

change image on click javascript

function changeImage() {
    if (document.getElementById("imgClickAndChange").src == "http://www.userinterfaceicons.com/80x80/minimize.png"){
        document.getElementById("imgClickAndChange").src = "http://www.userinterfaceicons.com/80x80/maximize.png";
    } else {
        document.getElementById("imgClickAndChange").src = "http://www.userinterfaceicons.com/80x80/minimize.png";
    }
}
Comment

change image onclick javascript

<p>
    <img alt="" src="http://www.userinterfaceicons.com/80x80/minimize.png" 
        style="height: 85px; width: 198px" id="imgClickAndChange" onclick="changeImage()"/>
</p>
<script>
function changeImage() {
    if (document.getElementById("imgClickAndChange").src == "http://www.userinterfaceicons.com/80x80/minimize.png"){
        document.getElementById("imgClickAndChange").src = "http://www.userinterfaceicons.com/80x80/maximize.png";
    } else {
        document.getElementById("imgClickAndChange").src = "http://www.userinterfaceicons.com/80x80/minimize.png";
    }
}
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: nestjs set swagger api keys 
Javascript :: factorial js 
Javascript :: js var vs let 
Javascript :: react router remove location state on refresh 
Javascript :: js local file read to blob variable 
Javascript :: angular build deploy url 
Javascript :: flutter http get json to map 
Javascript :: express.js get params 
Javascript :: tailwind css toggle switch react 
Javascript :: TypeError: navigation.getParams is not a function. 
Javascript :: cos in javascript 
Javascript :: puppeteer event element change 
Javascript :: filter react 
Javascript :: Reusable Alpine.js components 
Javascript :: jquery scroll to position 
Javascript :: remove trailing zeros javascript 
Javascript :: curl send json as variable 
Javascript :: vue js hooks 
Javascript :: react POST ERROR HANDLING 
Javascript :: redux toolkit how to set empty initial state 
Javascript :: setimeout 
Javascript :: js sort by two numeric fields 
Javascript :: automatically click button javascript on setinterval 
Javascript :: get role id from role position 
Javascript :: jquery onclick click 
Javascript :: js event div class adding 
Javascript :: javascript comments 
Javascript :: js copy text 
Javascript :: discord js embeded message hyperlink 
Javascript :: add background image react native 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =