PDA

View Full Version : Changing Node Values


Guardian-Mage
05-05-2007, 01:07 AM
Some HTML

<div class='news'>
<b class="news-head">News Flash: New Website by Guardian Technology </b>
<br />
<span class="news-subhead">Date: 2007-05-01</span>
<br />

<span class="news-subhead">New Website Again...OMG!</span>
<br />
<img style="border:0" src="images/default.bmp" width="200" height="133" alt="Jordan 2 Picture" />
<br />
Thanks to Brandon Wamboldt From Guardian Technolog...<br />
<span id="span1" class="readmore" style="cursor:pointer;" onclick="toggleDisplay('news1','span1')">
&gt;&gt;Read More</span>

<div style="display:none" id="news1"><p class="news-body">
Thanks to Brandon Wamboldt From Guardian Technology: Freelance Web Development, we have yet another new site. Hope you all like this one.
</p></div>
</div>
&nbsp;<div class='news'>
<b class="news-head">News Flash: Jordan Wilkens 2 Trailer </b>
<br />
<span class="news-subhead">Date: 2007-04-04</span>

<br />
<span class="news-subhead">WHAT?! JORDAN AGAIN!?!? NOOOOOOOOO!!!!!!!!</span>
<br />
<img style="border:0" src="images/jordan2trailer.jpg " width="200" height="133" alt="Jordan 2 Picture" />
<br />
We just released the Jordan Wilkens 2 Trailer on Y...<br />
<span id="span2" class="readmore" style="cursor:pointer;" onclick="toggleDisplay('news2','span2')">
&gt;&gt;Read More</span>

<div style="display:none" id="news2"><p class="news-body">
We just released the Jordan Wilkens 2 Trailer on Youtube. Go ahead and check it out. The movie stars Jordan Wilkens as Jordan Wilkens. Please vote for the new movie.
</p></div>
</div>
&nbsp;&nbsp;
</div>


Now I need it so when I click on Read More it changes ">>Read More" to "<<Hide All"

Javascript so far:

<!--
function toggleDisplay(which,other)
{
var myId = document.getElementById(which);
var otherID = document.getElementById(other);

if (myId.style.display=="block")
{
myId.style.display="none";
otherID.nodeValue="&gt;&gt;Read More";
}
else if (myId.style.display=="none")
{
myId.style.display="block";
otherID.nodeValue="&lt;&lt;Hide All";
}
}
-->


You can look at the site at
http://ictonentertainment.com/wamboldt/newicton/

rwedge
05-05-2007, 05:53 AM
Here's one way:function toggleDisplay(which,other) {
var myId = document.getElementById(which);
var otherID = document.getElementById(other);
var oldtxt = otherID.childNodes[0];
if (myId.style.display=="block") {
myId.style.display="none";
var newtxt = document.createTextNode('>>Read More');
otherID.replaceChild(newtxt,oldtxt);
}
else if (myId.style.display=="none") {
myId.style.display="block";
var newtxt1 = document.createTextNode('<<Hide All');
otherID.replaceChild(newtxt1,oldtxt);
}
}