There are a few ways to do this, one of them being the following:
1) Remove the extranous <font> tags in your markup, as they interfere with using CSS dynamically to color your links
2) Give each question link a unique ID in the form of divid+"link", where divid is the ID value of the DIV the link toggles
3) And finally, use the ontoggle event handler of the script to dynamically apply a different color to a link when it's clicked on and expands the corresponding content.
With that said, the below is the complete modified markup:
Code:
<!DOCTYPE HTML>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="animatedcollapse.js">
/***********************************************
* Animated Collapsible DIV v2.4- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
***********************************************/
</script>
<script type="text/javascript">
animatedcollapse.addDiv('q1', 'fade=5,speed=300,group=questions,hide=1')
animatedcollapse.addDiv('q2', 'fade=5,speed=300,group=questions,persist=0,hide=1')
animatedcollapse.addDiv('q3', 'fade=5,speed=300,group=questions,hide=1')
animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
if (state=="block")
$('a#'+divobj.id+'link').css('color', (state=='block')? 'red' : 'blue') //"red" when question has been expanded already, blue if never
}
animatedcollapse.init()
</script>
<p>
<a id="q1link" href="javascript:animatedcollapse.show('q1')">QUESTION</a><a href="javascript:animatedcollapse.hide('q1')"></a>
</p>
<div id="q1" style="width: 550px; background: #ffffff;">ANSWER</i>
</div>
<p>
<a id="q2link" href="javascript:animatedcollapse.show('q2')"><u>QUESTION</u></a><a href="javascript:animatedcollapse.hide('q2')"></a>
</p>
<div id="q2" style="width: 550px; background: #ffffff;">ANSWER
</div>
<p>
<a id="q3link" href="javascript:animatedcollapse.show('q3')"><u>QUESTION</u></a><a href="javascript:animatedcollapse.hide('q3')"></a>
</p>
<div id="q3" style="width: 550px; background: #ffffff">ANSWER
</div>
Bookmarks