View Full Version : Switch Content Script HELP

04-25-2005, 03:22 PM
I was looking for a little help on the Switch Content Script.

It's Working GREAT but...
when i click the link to expand the content the browser sends the view back to the very top.

here is the link to the DynamicDrive Script.

here is a link to my attempt of using this script. Note when you click the SHOW buttons on the Right (click them all) then scroll down to the bottome one and click the hide HIDE link then you will see the browser pop back to the top. I would like to see the browser stay where the link is.


04-25-2005, 06:16 PM
That is caused by your use of the href="#" which means, goto to the anchor name on this page with no name, or essentially, goto top. That was never suggested as a method when using this script. Here, from the demo page, are the suggested methods:

<!--Optional Expand/ Contact All links. Remove if desired-->
<div><a href="javascript:sweeptoggle('contract')">Contract All</a> | <a href="javascript:sweeptoggle('expand')">Expand All</a></div>

<h3 onClick="expandcontent(this, 'sc1')" style="cursor:hand; cursor:pointer"><span class="showstate"></span>What is JavaScript?</h3>
<div id="sc1" class="switchcontent">
JavaScript is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer.

<h3 onClick="expandcontent(this, 'sc2')" style="cursor:hand; cursor:pointer"><span class="showstate"></span>Difference between Java & JavaScript?</h3>
<div id="sc2" class="switchcontent">
Java is completely different from JavaScript- the former is a compiled language while the later is a scripting language.

<h3 onClick="expandcontent(this, 'sc3')" style="cursor:hand; cursor:pointer"><span class="showstate"></span>What is DHTML?</h3>
<div id="sc3" class="switchcontent">
DHTML is the embodiment of a combination of technologies- JavaScript, CSS, and HTML. Through them a new level of interactivity is possible for the end user experience.
</div>If you want to use an anchor (<a ....>something</a>) you can use it without any href= attribute, though that is unusual and may cause problems with some browsers. Substituting <span> tags should be fine. So for:

<a href="#" onClick="expandcontent(this, 'sc1')"style="cursor:hand; cursor:pointer"><span class="showstate"></span></a>you could try:

<span onClick="expandcontent(this, 'sc1')" style="cursor:hand; cursor:pointer"><span class="showstate"></span></span>Also, notice that you have left out a space between:

onClick="expandcontent(this, 'sc1')" and style="cursor:hand; cursor:pointer"

04-25-2005, 08:23 PM
I will give that a try, but eBay is using that method somehow.
the use the href to #


thats exactly how i was hoping it would look.


04-25-2005, 08:34 PM
Professor jscheuer1 you hit the nail on the head.

that worked perfect!! :)
Thanks a Ton for the quick help!!! :D