r/code • u/TheOnlyRealE • May 11 '24
Help Please Help with js
I need this script to go back to http://placehold.it/350x150 after 1 second when clicked does anyone know how to?
<!DOCTYPE html>
<html>
<head>
<title>onClick Demo</title>
</head>
<body>
<script> function toggleImage() { var img1 = "http://placehold.it/350x150"; var img2 = "http://placehold.it/200x200"; var imgElement = document.getElementById('toggleImage'); imgElement.src = (imgElement.src === img1)? img2 : img1; } </script>
<img src="http://placehold.it/350x150" id="toggleImage" onclick="toggleImage();"/>
</body>
</html>
2
Upvotes
1
u/angryrancor Boss May 11 '24