Spoiler not working in Firefox 2 :(

Discussion in 'JavaScript' started by blueparukia, Dec 23, 2007.

  1. #1
    Craptacular...

    My code:
    <div style="border:1px inset gray;width:100%;"><div><input type="button" value="Spoiler" class="button" 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';}; "" />
    Code (markup):
    That doesn't work in Firfox 2.x, any help would be appreciated.

    BP
     
    blueparukia, Dec 23, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It doesn't work for me in IE7 too, could you post a bit more of surrounding code, like example for a working spoiler text?
     
    hogan_h, Dec 23, 2007 IP
  3. locdev

    locdev Active Member

    Messages:
    171
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I don't understand what you need but
    here is an example of working script:



    <script language="JavaScript">
    <!--
    function spoilerClick(el){
    if (el.parentNode.childNodes[1].innerHTML == 'Hide Spoiler'){
    	el.parentNode.childNodes[1].style.display = 'none'; 
    	el.parentNode.childNodes[1].innerHTML = 'Show Spoiler';
    }
    else{
    	el.parentNode.childNodes[1].style.display = 'inline'; 
    	el.parentNode.childNodes[1].innerHTML = 'Hide Spoiler';
    	}; 
    }
    //-->
    </script>
    <div style="border:1px inset gray;width:100%;"><div><input type="button" value="Spoiler" class="button" onclick="spoilerClick(this)" /><div></div></div></div>
    Code (markup):
     
    locdev, Dec 24, 2007 IP
  4. jronmo

    jronmo Guest

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <div id="spoiltext" style="display:none; border: 1px inset gray; width: 100%;">
    Spoiler Text
    </div>
    <div>
    <input
      type="button"
      value="Show Spoiler"
      class="button"
      onclick="this.value = ((this.value == 'Show Spoiler') ? 'Hide Spoiler':'Show Spoiler'); document.getElementById('spoiltext').style.display =               ((document.getElementById('spoiltext').style.display == 'none')? 'inline':'none');" />
    </div>
    Code (markup):
     
    jronmo, Dec 27, 2007 IP