Is it possible to have the word count displayed in the link that shows the hidden text? This website uses it quite a lot for their show/hide script, scroll down and you'll see. PS. Sorry for creating another thread on this script but this should be the last addition I need. Demo: http://www.murraysworld.com/test.php Javascript, <!-- function dsp(loc){ if(document.getElementById){ var foc=loc.firstChild; foc=loc.firstChild.innerHTML? loc.firstChild: loc.firstChild.nextSibling; var th = document.getElementById(loc); if(th != null){ //th.innerHTML=th.innerHTML=='+'?'-':'+'; foc.innerHTML=foc.innerHTML=='+'?'-':'+'; } foc=loc.parentNode.nextSibling.style? loc.parentNode.nextSibling: loc.parentNode.nextSibling.nextSibling; foc.style.display=foc.style.display=='block'?'none':'block';}} if(!document.getElementById) document.write('<style type="text/css"><!--\n'+ '.more_content{display:block;}\n'+ '//--></style>'); //--> Code (markup): HTML, <span class="more_intro"><a href="javascript:void(0)" onClick="dsp(this)">Click here for further info...</a></span> <span class="more_content">Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, <br /> </span> Code (markup): Thanks
Simple to someone who knows Javascript I wouldn't know what to do from your post MMJ but thanks for your input.
if you're going to use MMJ's suggestion.. it's implementation would be similar to this.. (the body part of your page) <span class="more_intro"><a id="theLink" href="javascript:void(0)" onClick="dsp(this)">Click here for further info...</a></span> <span id="more_content" class="more_content">Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, Further info, <br /> </span> <script type="text/javascript"> var wordCount = document.getElementById('more_content').innerHTML.split(" ").length; document.getElementById('theLink').innerHTML += " ("+wordCount+" words)"; </script> Code (markup): take note of the element IDs. It doesn't give the exact number of words but there should be a work around..
The way the script works now means I don't need to specify a unique ID for each expandable bit of text, that's very important to me.. with what you give I think I would need to do that otherwise all the links would have the same word count, right?
Yeah.. without the ID's that won't work. But then without using ID's, it will be very difficult to match the expandable blocks with the link. I'm just curious, why can't you use a unique ID for each expandable block?
I have this script implemented into my forum using custom BBC codes I have coded in. Having it use an ID would be to difficult for me to implement but without IDs is quite simple.
I use my forum as a CMS and I use this script by the custom BBC codes I have made - for example, [more_intro]Read on[/more_intro][more]Continued information[/more]. Having it use an ID would make it very difficult for me to implement into my forum.