how to swap two images in javascript

Solutions on MaxInterview for how to swap two images in javascript by the best coders in the world

showing results for - "how to swap two images in javascript"
Dina
30 Jan 2021
1<img src="ble.jpg" id="F" data-value="" onclick="swap(5)" />
2<img src="ilk.jpg" id="4" data-value="2" onclick="swap(6)"/>
3
4var img_1_value = document.getElementById("F").getAttribute('data-value');
5var img_2_value = document.getElementById("4").getAttribute('data-value');
6
7document.getElementById("F").setAttribute('data-value', img_2_value);
8document.getElementById("4").setAttribute('data-value', img_1_value);
9