I have a website that looks like below. When a text is clicked, the clicked text will get a class called large and the text size will change to 25pt. To see how I am assigning the event and the class large, please look at the js code. The problem I have is when the text "I like swimming" is clicked the large class gets added to the text "I like basketball". Why is this happening? Can anyone help me to fix this issue?
const arraySportsText = Array.from(document.getElementsByClassName('sportsText'));
for (index in arraySportsText) {
arraySportsText[index].addEventListener("click", () => arraySportsText[index].classList.add('large'))
}
body {
font-size: 15pt;
}
.large {
font-size: 25pt;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles/style.css">
</head>
<body>
<h1>Sports</h1>
<p class="sportsText">I like swimming</p>
<p class="sportsText">I like basketball</p>
<script src="scripts/hobby.js"></script>
</body>
</html>