Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

onclick change image src 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 :: github remote 
Javascript :: counter with react hooks 
Javascript :: async await in javascript 
Javascript :: jsjs trigger window error 
Javascript :: how to make a check if 50% of letters are capital in discord js 
Javascript :: unzip file electronjs 
Javascript :: react media recoder 
Javascript :: projection in mongodb 
Javascript :: pm2 config changes update environments 
Javascript :: Vue JS Production mode refresh causing 404 error 
Javascript :: Check for mobile device 
Javascript :: onclick on fragment react 
Javascript :: How to convert a canvas to an image javascript 
Javascript :: babel debugging 
Javascript :: mongodb check if collection exists 
Javascript :: react native asign width to image 
Javascript :: which object key has highest value javascript 
Javascript :: class component react 
Javascript :: jquery get fail 
Javascript :: how to convert utc time to local time angular 
Javascript :: input from terminal node js 
Javascript :: mongodb working with date 
Javascript :: js catch all images errors 
Javascript :: jquery find input and select 
Javascript :: ajax get request parameters 
Javascript :: get index of item with attribute javascript 
Javascript :: react hook form reset only one field 
Javascript :: javascript time of execution 
Javascript :: java script alert 
Javascript :: convert array of javascript into string with comma 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =