Spoiler tag

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Spoiler tag

Post by Cirdan »

I'm trying to create a spoiler tag for my site, but I can't figure out the Javascript.

I have this html:

Code: Select all

<div class='spoiler'>
                    <a href='javascript&#058;void(0)' onclick='toggleView(this.parentNode.getElementById("goods"))'>Show / Hide Spoiler</a>
                    <div id='goods' style='display: none'>
                    \\1
                    </div>
                </div>
And this javascript:

Code: Select all

function toggleView(node)
{
    if(node.display == 'none')
    {
        node.style.display = '';
    }
    else
    {
        node.style.display = 'none';
    }
        
}
Whenever I click the button to hide or show the spoiler...FF tells me that "this.parentNode.getElementById" is not a function. What am I missing? Is it easier just to generate a random ID and try to select it from the whole document?
Last edited by Benjamin on Fri May 29, 2009 10:54 am, edited 1 time in total.
Reason: Changed code type from text to javascript.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Spoiler tag

Post by jayshields »

Try removing this.parentNode from your JavaScript function call.
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Re: Spoiler tag

Post by Cirdan »

Nope...no error and the div doesn't show
Post Reply