open accordion by hash

by ian_smithz

JavaScript

document.addEventListener("DOMContentLoaded", function () {

    var hash = window.location.hash; 

    // changing hash to class to avoid rewriting all the automatically generated aria attributes and ids
    // putting 'ac__title-1' on a direct link to an accordion panel is a bit ugly

    hash = hash.substr(1);
    hash = '.' + hash;

    jQuery(hash).parent().addClass('ac__item--open'); 
    jQuery(hash).attr({'aria-expanded':'true', 'aria-selected':'true'});
    jQuery(hash).next().css('display', 'block');
    //jQuery(hash).focus();

});








jQuery(document).ready(function() {

    var hash = window.location.hash; 

    jQuery(hash).parent().addClass("ac__item--open"); 
    jQuery(hash).attr({"aria-expanded": "false", "aria-selected": "true"});
    jQuery(hash).next().css("display", "block");
    
});