views:

93

answers:

1

Hi friends, I want to expand hidden text on a webpage and after some (re)search on google i came across the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;

<head>
<title>Test</title>


<script type="text/javascript">
function Expand(node)
{
  // Change the image (if there is an image)
  if (node.childNodes.length > 0)
  {
    if (node.firstChild.tagName == "IMG")
    {
      node.firstChild.src = "minus.gif";
    }
  }
  node.nextSibling.style.display = '';
}

function Collapse(node)
{
  // Change the image (if there is an image)
  if (node.childNodes.length > 0)
  {
    if (node.firstChild.tagName == "IMG")
    {
      node.firstChild.src = "plus.gif";
    }
  }
 node.nextSibling.style.display = 'none';
}

function Toggle(node)
{
  // Unfold the branch if it isn't visible
  if (node.nextSibling.style.display == 'none')
  {        
      Expand(node);
  }
  // Collapse the branch if it IS visible
  else
  {        
     Collapse(node);
  }
node.childNodes[1].nodeValue = (node.nextSibling.style.display == 'none')? 'More...' : 'Less...';
}           
</script> 

</head>


<body>


<a onclick="Toggle(this)" style="cursor:pointer;"><img src="plus.gif" alt="Expand/Collapse" /> More...</a><p style="display:none;">This is a sample of the expanded text that will show up when "+ More..." is clicked</p>              


</body>
</html>

Now the script displays a .gif image of a plus sign(expand) with 'More...' beside it and when the .gif file or the 'More...' is clicked the hidden text appears and the plus.gif is replaced with a minus.gif and 'More...' changes to 'Less...' but i want to implement it in another way, i want that once the expand (plus.gif) is clicked, no other .gif should appear again, i dont know how to modify the code to do it, so friends please help me out

i am a newbie in javascript so such a dumb doubt had to come

Thanx :)

+1  A: 

Just change your code to this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <head>
        <title>Test</title>
        <script type="text/javascript">

            function ExpandDelete(node)
            {
                if (node.nextSibling.style.display == 'none')
                {        
                    node.nextSibling.style.display = '';
                    node.parentNode.removeChild(node);
                }
            }           
        </script> 
    </head>

    <body>
        <a onclick="ExpandDelete(this);" style="cursor:pointer;"><img src="plus.gif" alt="Expand" /> More...</a><p style="display:none;">This is a sample of the expanded text that will show up when "+ More..." is clicked</p>              
    </body>
</html>
Vincent McNabb
i deleted the code as u said but nothing changed, except the image 'plus.gif' is now not replaced by 'minus.gif',the 'plus.gif' remains throughout...
Brad
that doesnt work either :|
Brad
The modified code does remove the image. What exactly is it you want to do?
Vincent McNabb
I want that 'minus.gif' and the text beside it 'Less..' both should be removed but by doing the above modification only 'minus.gif' is removed. The text 'Less..' is still there, please help
Brad
thanx a lot mate :)
Brad