I am trying to make the arrow toggle to display the row data when clicked. At the same time, I’d like the arrow to turn from right to down. This would all reverse when clicked again to hide the row and change the arrow back. I know the code is plain html, I’ll clean it up later for sure. My knowledge with scripts and more advanced CSS, is very limited. Thank you for any assistance.
I tried searching for the past few days, but have had minimal luck. I may be asking the question wrong when searching.
My HTML below:
<!DOCTYPE html>
<html>
<head>
<title>Breaking News</title>
</head>
<body bgcolor="#EEEEEE" link="0000FF" vlink="0000FF" alink="0000FF">
<table width="400" cellspacing="1" cellpadding="5" align="center" bgcolor="#CCCCCC" align="center">
<tr>
<td align="center" valign="middle" bgcolor="#000000" width="" colspan="7"><span style="color: #FFFFFF; font-family: Arial,Helvetica,sans-serif; font-size: 14px;"><b>Breaking News</b></span></td>
</tr><tr>
<td align="left" valign="middle" width="" bgcolor="#CCCCCC"><span style="color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px;"><b>Date</b></span></td>
<td align="left" valign="middle" width="" bgcolor="#CCCCCC"><span style="color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px;"><b>Subject</b></span></td>
</tr><tr>
<td align="left" valign="middle" width="" bgcolor="#FFFFFF"><span style="color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px;">Aug 22, 2023 / 10:00a</span></td>
<td align="left" valign="middle" bgcolor="#FFFFFF" width=""><span style="color: #0000FF; font-family: Arial,Helvetica,sans-serif; font-size: 14px;"><span style="color: #000000; cursor: pointer;">▶</span> <a href="#">Article Name Here</a></span></td>
</tr><tr>
<td align="left" valign="middle" width="" bgcolor="#FFFFFF"><span style="color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px;">Aug 22, 2023 / 9:00a</span></td>
<td align="left" valign="middle" bgcolor="#FFFFFF" width=""><span style="color: #0000FF; font-family: Arial,Helvetica,sans-serif; font-size: 14px;"><span style="color: #000000; cursor: pointer;">▼</span> <a href="#">Article Name Here</span></td>
</tr><tr>
<td align="left" valign="middle" bgcolor="#FFFFFF" width="" colspan="2">
<span style="color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px;">
Content I'd like displayed when the arrow is clicked<br>
</span>
</td>
</tr><tr>
<td align="left" valign="middle" width="" bgcolor="#FFFFFF"><span style="color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px;">Aug 22, 2023 / 8:00a</span></td>
<td align="left" valign="middle" bgcolor="#FFFFFF" width=""><span style="color: #0000FF; font-family: Arial,Helvetica,sans-serif; font-size: 14px;"><span style="color: #000000; cursor: pointer;">▶</span> <a href="#">Article Name Here</a></span></td>
</tr>
</table>
<br>
</body>
</html>
3
Answers
Create a div to contain all the elements you want to hide/show and give it an ID.
In JS you can toggle this div’s visibility via
Reference for toggling elements
To rotate an arrow you can use css transforms. Reference this
1-i sugggest you to use font awesome instead of emoji codes.
2-use onclick event.
<span onclick="toggleArrow()"> </span>
for font awesome
<i onclick="toggleArrow()" class="fa-solid fa-square-chevron-right"></i>
3-define id
<i id="arrow" onclick="toggleArrow()" class="fa-solid fa-square-chevron-right"></i>
4-define your function in script tag end of body `
function toggleArrow(){
…
}
`
5-you can change the icons by changing class of tag
6-access to class of elements using
document.getElementById("arrow").classList
7-deleting class using
document.getElementById("arrow").classList.remove()
8-add class using
document.getElementById("arrow").classList.add("anyClassName")
9-use if condition in your function to change the class
I have added the feature you wanted perfectly. Click on the first and the last icons to see the result. The required CSS and JS are given below with necessary comments: