Spoiler Code improvement needed

Discussion in 'JavaScript' started by blueparukia, Jul 31, 2007.

  1. #1
    I am a very poor Javascript coder......


    I made a spoiler tag for my forums, and I want some things added to it.

    The code is:

    <small>    <b>Spoiler:</b></small><br /> <div style="border: inset 1px gray; padding: 1px;"><div><button type="button" class="button" onclick="this.parentNode.parentNode.childNodes[1].style.display = ''; this.parentNode.style.display = 'none';" title="Click to show the spoiler."><font color="#000000" size="1"><b>Show Spoiler</b></font></button></div><div id="spoiler" style="display: none;"> <br />
    Code (markup):
    I want a few alterations and additions to it...(shouldn't be too hard).

    Preview is here: http://doghousegifts.net/Upload/showthread.php?tid=2&page=1

    I want the button to remain after clicked, and when you click it again, the spoiler is hidden.


    Could anyone please do this for me?

    Thanks,

    BP
     
    blueparukia, Jul 31, 2007 IP
  2. disco_danny

    disco_danny Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    blueparukia,
    Try replacing your onclick with the following code:

    onclick="if (this.innerHTML == 'Hide Spoiler'){this.parentNode.parentNode.childNodes[1].style.display = 'none'; this.innerHTML = 'Show Spoiler';}else{this.parentNode.parentNode.childNodes[1].style.display = 'inline'; this.innerHTML = 'Hide Spoiler';}; "

    The style of the font changes, but you should be able to control it through CSS or the style attribute.

    Hope this helps.

    Disco_Danny
     
    disco_danny, Aug 1, 2007 IP
  3. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #3
    Works perfect, thanks so much
     
    blueparukia, Aug 1, 2007 IP