function yourFunction() {
let displayImage = document.getElementById('imahe')
if(displayImage.src.match('images/cabato.jpg')){
displayImage.src = 'images/nin.jpg'
}
else {
displayImage.src = 'images/cabato.jpg'
}
}
Im using simple if/else, need to know how to still make this work by using global boolean variable
3
Answers
There’s no need for a variable at all. You can use a simple ternary operator to solve this for a toggle operation.
One way is state variable
flag
and toggle on button click and re-render image.I post you a code snippet easy to understand and to modify less.