I have come across similar questions, but in my case, I am working with dynamic data from an API. I want the message body to show when a user clicks on a message with only the subject, and then be able to click again to hide the body. The current functionality works fine, but I would like to add that feature.
if(data.status == 200){
data.data.forEach(message => {
msg += `
<div id="read">
<p id="header">${message.subject}<span>......</span></span></p>
<p id="body">${message.message_details}</p>
<p>Sent on: ${message.created_on}</p>
</div>
<hr>`
});
document.getElementById("inbox").innerHTML = msg
}