Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Conversation

@abstractlabs
Copy link

In one project I am working on I found the need to mix hash and url anchors using the .tabs class. When using a URL anchor they would display correctly but would generate console errors. The one liner simply checks to see of the href starts with a hash tag before triggering the show() method on document ready.

@tekreme73
Copy link

My response :

  • a[href+="#"] => a[href*="#"]
  • split href to get the element id

Example in kickstart.js :

// tab click
$(document).on('click', 'ul.tabs a[href*="#"]', function(e){
    e.preventDefault();
    var tabs = $(this).parents('ul.tabs').find('li');
    var tab_next = $(this).attr('href');
    var tab_current = tabs.filter('.current').find('a').attr('href');

    var aCur = tab_current.split("#");
    var idCur = aCur.length > 0 ? aCur[ aCur.length - 1 ] : '';
    $("#" + idCur).hide();

    tabs.removeClass('current');
    $(this).parent().addClass('current');

    var aNext = tab_next.split("#");
    var idNext = aNext.length > 0 ? aNext[ aNext.length - 1 ] : '';
    $("#" + idNext).show();

    history.pushState( null, null, window.location.search + $(this).attr('href') );
    return false;
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants