Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active November 17, 2018 07:01
Show Gist options
  • Save harrisonmalone/14b4247c047724eb2d136c5c607508cc to your computer and use it in GitHub Desktop.
Save harrisonmalone/14b4247c047724eb2d136c5c607508cc to your computer and use it in GitHub Desktop.
using an event listener on an image to toggle a class that makes it round
const image = document.querySelector("img")
image.addEventListener("click", function(event) {
event.target.classList.toggle("round")
})
* {
margin: 0px;
}
.normal {
height: 400px;
width: 400px;
}
.round {
border-radius: 50%;
}
.wrapper {
display: flex;
height: 100vh;
justify-content: center;
align-items: center;
margin: 0 auto;
max-width: 700px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<script defer src="script.js"></script>
</head>
<body>
<div class="wrapper">
<img class="normal" src="https://proxy.duckduckgo.com/iu/?u=http%3A%2F%2Fstatic3.businessinsider.com%2Fimage%2F5484d9d1eab8ea3017b17e29%2F9-science-backed-reasons-to-own-a-dog.jpg&f=1">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment