How can I create several spoiler buttons using javascript / html?

Julie S

New member
Hi! I found the code for inserting a spoler button (Show/Hide) into my webpage:

<div style=" margin-top:5px"><div class="quotetitle"><b>? ?????? ???????? ? ?????????? ??????:</b> <input type="button" value="Show" style="width:60px;font-size:10px;margin:0px;padding:0px;" onclick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }" /></div><div class="quotecontent"><div style="display: none;">Text here</div></div></div>

However, it only works for one button per page. Copying and pasting does nothing (the second button either doesn't click or opens the same first spoiler). I'm fairly new to all of this and I couldn't find an answer online. I would appreciate any help!

Julie
 
Back
Top