//= require govuk_toolkit
//= require_tree .

jQuery(function($) {

  "use strict";
  GOVUK.primaryLinks.init('.primary-item');

  $('.js-collapsible-collection').each(function(){
    new GOVUK.CollapsibleCollection({$el:$(this)});
  })

  if (window.location.hash) {
    openSectionContainingAnchor($(window.location.hash));
  }

  $('.govspeak').on('click', 'a', function(event){
    if (window.location.pathname == event.target.pathname) {
      openSectionContainingAnchor($(window.location.hash));
    }
  })
});


function openSectionContainingAnchor($anchor) {
  if ($anchor.length != 0) {
    new GOVUK.Collapsible($anchor.closest('.js-openable')).open();
  }
}

//= require govuk_toolkit
//= require_tree .

jQuery(function($) {

  "use strict";
  GOVUK.primaryLinks.init('.primary-item');

  $('.js-collapsible-collection').each(function(){
    new GOVUK.CollapsibleCollection({$el:$(this)});
  })

  if (window.location.hash) {
    openSectionContainingAnchor($(window.location.hash));
  }

  $('.govspeak').on('click', 'a', function(event){
    if (window.location.pathname == event.target.pathname) {
      openSectionContainingAnchor($(event.currentTarget.hash));
    }
  })
});


function openSectionContainingAnchor($anchor) {
  if ($anchor.length != 0) {
    new GOVUK.Collapsible($anchor.closest('.js-openable')).open();
  }
}

Update anchor parameter to be derived from event
Update anchor parameter to be derived from event

Using window.location.hash previously does not get updated by the time the click event takes place. As window.location.hash is not set to the correct anchor element, the intended section does not open.
Changing this to get the anchor element from the clicked target fixes that.
