View Full Version : Shorten collapsing code?


Lady Serena
08-30-2005, 12:34 AM
Is there any way to make this collapsing code shorter? Since I can't actually assign unique IDs to these forum elements, I can't use the toggle() function, but I would like to shorten this code.

Quote with membername:
<!-- BEGIN quote_username_open --></span>
<table width="95%" cellspacing="0" cellpadding="0" border="1" align="center">

<tr>

<td border="0" class="quote" style="margin: 0px">

<span style="font-size: 11px;">

<div style="margin:2px">

<div class="smallfont" style="margin:0px;padding:0px;">
<img value="{Q_BUTTON}" src="{Q_BUTTON}" style="{B_STYLE}" onClick="if (this.parentNode.parentNode.getElementsByTagName(' div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('d iv')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = '{B_HIDE}'; } else { this.parentNode.parentNode.getElementsByTagName('d iv')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = '{B_SHOW}'; } this.src = this.value;"> <b>{USERNAME} {L_WROTE}:</b>

</div>

<div style="margin: 0px; padding: 0px; border: 0px inset; border-style: solid;">

<div class="postbody" style="display: {Q_STATUS}; border-top: 1px #000000 solid; padding: 2px; padding-bottom: 0px;"><!-- END quote_username_open -->


Quote without membername:
<!-- BEGIN quote_open --></span>
<table width="95%" cellspacing="0" cellpadding="0" border="1" align="center">

<tr>

<td border="0" class="quote" style="margin: 0px">

<span style="font-size: 11px;">

<div style="margin:2px">

<div class="smallfont" style="margin:0px;padding:0px;">

<img value="{Q_BUTTON}" src="{Q_BUTTON}" style="{B_STYLE}" onClick="if (this.parentNode.parentNode.getElementsByTagName(' div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('d iv')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = '{B_HIDE}'; } else { this.parentNode.parentNode.getElementsByTagName('d iv')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = '{B_SHOW}'; } this.src = this.value;"> <b>{L_QUOTE}:</b>

</div>

<div style="margin: 0px; padding: 0px; border: 0px inset; border-style: solid;">

<div class="postbody" style="display: {Q_STATUS}; border-top: 1px #000000 solid; padding: 2px; padding-bottom: 0px;"><!-- END quote_open -->

Close quote:
<!-- BEGIN quote_close --></div></div></div></span></td></tr>
</table><div style="padding-top: 2px"></div><!-- END quote_close -->

I'd like to shorten the JavaScript code used for the show/hide button, but JavaScript is a foreign language to me. Again, I can't assign a unique ID to these elements, so the use of toggle() is unavailable. How can I shorten the code for the show/hide button?