1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

a href="#" adds current site, anyway to disable it?

Discussion in 'XenForo Development Discussions' started by rivacom, Oct 27, 2015.

  1. rivacom

    rivacom Active Member

    I'm trying to setup a series of menus and div content on a xenforo page. However, anytime I create a link with #, it just adds my url infront of the #. Anyway to disable this for pages?
     
  2. Jake B.

    Jake B. Well-Known Member

    That's what using # in the href is supposed to do, what is it that you're wanting to do?
     
  3. rivacom

    rivacom Active Member

    I have a Menu and when I click say menu link 1, it loads a div content using jquery. From my understanding(which I guess maybe i'm overlooking something) # has always been a bookmark reference, not reloading the page but rather looking for a ID with the same name.
    Javascript
    Code:
    <script>
    $(document).ready(function () {
        $('#menu').on('click', 'a', function () {
           if($(this).closest('li').hasClass('current')) return; $('.current').not($(this).closest('li').addClass('current')).removeClass('current');
            // fade out all open subcontents
            $('.pbox:visible').hide(600);
            // fade in new selected subcontent
            $('.pbox[id=' + $(this).attr('data-id') + ']').show(600);
        }).find('a:first').click();
    });
    </script>
    Link
    HTML:
    <a href="#heroes">
    Div
    Code:
    <div class="pbox" id="heroes">
     
    Last edited: Oct 27, 2015
  4. Jake B.

    Jake B. Well-Known Member

    use <a href="javascript:void(0)"> instead of <a href="#"> :)
     
  5. rivacom

    rivacom Active Member

    That actually works better, not sure why I didn't think of that. Thanks!
     

Share This Page