I want to toggle a CSS style to the button elements. The problem is that the JavaScript code is not working.
This is what I did. The changeFont() function is not working.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
<style>
.invisible {
font-family: 'Anton' 'sans-serif';
}
</style>
</head>
<body>
<button onclick="changeFont()">Abraham Abah</button>
<button onclick="changeFont()">Work</button>
<button onclick="changeFont()">Lab</button>
<script>
function changeFont() {
let toggleFontFamily = document.querySelectorAll("button");
for (let i = 0; i < toggleFontFamily.length; i++) {
if (toggleFontFamily[i] == toggleFontFamily[0]) {
toggleFontFamily[0].classList.toggle("invisible");
} else if (toggleFontFamily[i] == toggleFontFamily[1]) {
toggleFontFamily[1].classList.toggle("invisible");
} else {
toggleFontFamily[2].classList.toggle("invisible");
}
}
}
</script>
</body>
</html>