바닐라 JS 클릭 버튼 구현 코드
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=
, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<span>Total clicks: 0 </span>
<button id="btn">Click</button>
</body>
<script>
let counter = 0;
const button = document.getElementById("btn")
const span = document.querySelector("span")
function handleClick(){
console.log("I have been click")
counter += 1
span.innerText = `Total clicks : ${counter}`;
}
button.addEventListener("click", handleClick)
</script>
</html>
구현 화면