Change text using an event handler
Hi.
I'm trying to change a word in an animated collapsible div script from
Dynamic Drive. When clicking "Hide" I want the word to change to "Show". I have part of the script, but it's not working correctly - it just removes "Hide" when clicking on it.
See the example here.
The code so far is this:
-
animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
//$: Access to jQuery
//divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
//state: "block" or "none", depending on state
if ($('#'+divobj.id+'-toggle').length==1){ //if toggle link has id 'divid-toggle' defined
if (state=="block")
$('#'+divobj.id+'-toggle').prepend('<span class="prefix">Hide </span>')
else
$('#'+divobj.id+'-toggle').find('span.prefix').remove()
}
}
I'm totally new to jQuery. Can anyone help me out?
Thanks in advance.