Change image source via button click

HTML
<button type=”button” id=”button”>change image</button>
 
JavaScript

var btn = document.getElementById(“button”);

btn.addEventListener(“touchstart”,

function(){

var imageContainer = document.getElementById(“Unique-ID”);

var image = imageContainer.children[0];

image.src = “https://path/to/image.jpg”;

});

Description

var imageContainer = document.getElementById(“Unique-ID”); is the parent of the image augmentation. An example for the Unique-ID would be 49cc2a69-a733-41dd-8264-e27262bee30e.

To change the src of the image you have to get the child because an augmentation creats a including and tag.

For example:

<div>

<img src=”cat.jpg”/>

</div

Screenshot

Note: CSS and second button added for testing purposes.

© 2018 Konica Minolta Business Solutions Europe GmbH

Close Menu
Close Panel