View Full Version : adding an html anchor to an onclick toggle event

09-16-2011, 08:59 AM
Complete newb trying to break apart existing code to add some additional function.

This is the working code:

<a class="hackadelic-sliderButton" title="click to collapse panel" onclick="toggleSliderOfGroup('.a-32', '#hackadelic-sliderPanel-1')" href="javascript:;">Close Panel </a>

What I would like to do is add in an html anchor so that the browser relocates to the top of the page just as the panel toggles closed. ie

<a href="#topofpage"></a>

I realize I may not even be in the right forum but I'm trying! thanks.

Old Pedant
09-16-2011, 05:16 PM
At the top of the page:

<a name="topOfPage"></a>


<a class="hackadelic-sliderButton" title="click to collapse panel"
onclick="toggleSliderOfGroup('.a-32', '#hackadelic-sliderPanel-1'); return true;"
href="#topOfPage">Close Panel </a>

The return true; may not be needed, but it won't hurt and will ensure that the normal action of the <a> is performed *in addition* to the JS triggered by the onclick. And of course now the normal action is exactly what you wanted.

09-16-2011, 07:45 PM
Thanks for the quick reply. This is not working (the code remains visible when dropped into the page). I tried a few variations but still a problem.

I noted that you dropped the
href="javascript:;" Could that have something to do with it? When putting that back in, still fail - probably due to improper syntax on my part.

Old Pedant
09-16-2011, 09:55 PM
href="javascript" *means* "do NOT perform the normal action of an <a> link." So if that's there, it will never work.

(Well, it *could* be made to work, but only by adding more complexity.)

09-19-2011, 08:47 PM
It worked after dropping the return true. Thanks.