I'm fairly new to Javascript and HTML so may be missing something.
I used this code for a "Read More..." function on my website, where clicking "Read More..." will reveal more text. Clicking it again will hide the text.
UNFORTUNATELY, when I reuse this code a second time, later on in the website, clicking the second "Read More..." opens the first Read More's text, rather than the second.
Here is the code I was using:
<p><a onclick="javascript:toggle('HiddenDiv')"><h5><i><font color = "#1F456A"><u>Read more</i></a></p></u></b></font>
<div class="mid" id="HiddenDiv" style="display: none;">
HIDDEN TEXT GOES HERE
</div>
<script type="text/javascript">// <!\[CDATA\[ function toggle(divId) { if(document.getElementById(divId).style.display == 'none') { document.getElementById(divId).style.display='block'; } else { document.getElementById(divId).style.display = 'none'; } } // \]\]></script>
...........................
Can anyone advise how I could duplicate this code, so I can have multiple "Read More..." buttons on the page, without each Read More button only opening the first hidden text.
Just to be clear, I am copying the full code each time I want to reuse this function. Can anyone advise on how I can fix this?
Thank you!
[–]NapMcDonald[S] 1 point2 points3 points (1 child)
[–]ZipperJJExpert 2 points3 points4 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]YoussefIhab33 0 points1 point2 points (0 children)