document.getElementById("first-img").addEventListener("click", function(){
document.getElementById("detail-img").innerHTML = `Detail of first img`
})
document.getElementById("second-img").addEventListener("click", function(){
document.getElementById("detail-img").innerHTML = `Detail of second img`
})
.container{
display: flex;
height: 30px;
gap: 1rem;
}
.img{
background-color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="container">
<div class="img" id="first-img">This is image-1</div>
<div class="img" id="second-img">This is image-2</div>
</div>
<p id="detail-img">Click image for detail</p>
</body>
</html>
So i want to #detail-img be animated when click the image. the animation is like opacity to 0 to opacity 1, not just instant. I have try with animation css property but i was failed, nothing change. any clue to do that?