Can't seem to find much help about this anywhere, so i thought that I would try here.
I'm trying to make a simple for loop where when I hover over an html card, it hides some of the text in the card. The card has a simple first and last name, and I want to hide just the last name. I am able to make the whole card disappear by using the "this" object in the for loop, but I don't understand how to just make the text disappear. Any help would be appreciated as I'm still learning a lot about JS as I go.
Thanks!
let card = document.querySelectorAll(".card");
for (i = 0; i < card.length; i++) {
card[i].addEventListener("mouseover", function() {
this.classList.toggle("hide");
});
}
for (i = 0; i < card.length; i++) {
card[i].addEventListener("mouseout", function() {
this.classList.toggle("hide");
});
}
body {
margin: 0;
}
.card {
background-color: grey;
border-radius: 4px;
width: 100px;
height: 100px;
border: 1px black solid;
display: inline-block;
margin: 10px;
}
.hide {
visibility: hidden;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="card.css">
<title>test</title>
</head>
<body>
<div class="card">
<span class="first">first name</span>
<span class="last">last name</span>
</div>
<div class="card">
<span class="first">first name</span>
<span class="last">last name</span>
</div>
<script type="text/javascript" src="card.js"></script>
</body>
</html>
mouseenterinstead ofmouseover.