Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    adding an html anchor to an onclick toggle event

    Complete newb trying to break apart existing code to add some additional function.

    This is the working code:

    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

    Code:
    <a href="#topofpage"></a>
    I realize I may not even be in the right forum but I'm trying! thanks.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    At the top of the page:
    Code:
    <a name="topOfPage"></a>
    Then:
    Code:
    <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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Code:
    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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    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.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It worked after dropping the return true. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •