I have a very large set of stacked divs containing id
anchors and embedded videos wrapped in details
and summary
tags. Is it possible to simultaneously expand the details
and scroll to its id
in a single click? If I use the script below, I can scroll to an anchor with the a
tag:
/* JS */
$(document).ready(function(){
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 400, 'swing', function () {
window.location.hash = target;
});
});
});
/* HTML */
<div id="anchor></div>
<a href="#anchor">Scroll to anchor</a>
However, wrapping the summary
or details
itself in the a
tag will disable this scrolling effect.
/* HTML */
<div id="anchor">
<details><a href="#anchor"><summary>Embedded Video</summary></a>
<div class="youtube-player" data-id="null"></div>
</details>
</div>
I've tried a number of different variations, but I can't seem to get the combined effect of expand + scroll. What's the right approach for solving this issue?