Skip to content Skip to sidebar Skip to footer

Only Show Specific Div With Anchor

First of all, my coding skills are very basic so please bear with me. I am making a website for an art exhibition which has many people contributing. I have a page called profile

Solution 1:

Assuming you have:

  • A wrapper with class="profile" around each profile
  • And id on each pofile wrapper, matching your hash (like "example.name")

Then I believe you want something like this:

// On page load
$(document).ready(function(){

    // React to clicks on anchorswindow.onhashchange = hashChanged;

    // React to directly type urlshashChanged();

});

// When the URL hash (#something) changesfunctionhashChanged() {
    // hide all profiles
    $('.profile').hide();
    // get the current hasj minus '#'var profileId = window.location.hash.substr(1);
    // show only the appropriate profile
    $('#' + profileId).show();
}

Post a Comment for "Only Show Specific Div With Anchor"