Page 1 of 1

Spoiler tag

Posted: Thu May 28, 2009 3:01 am
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?

Re: Spoiler tag

Posted: Thu May 28, 2009 4:29 am
by jayshields
Try removing this.parentNode from your JavaScript function call.

Re: Spoiler tag

Posted: Thu May 28, 2009 10:04 pm
by Cirdan
Nope...no error and the div doesn't show