Допустим, у меня есть текст:
<div class="text">Here is some text.
In this text there are links <a href="#" class="link" id="an1">here</a>
and there are links <a href="#" class="link" id="an2">there</a>.
And there are probably many more!
They each open their own annotation on the side.</div>
И у меня есть следующие аннотации, которые я хочу открыть:
<div class="annotation" id="an1">I'm the first annotation!</div>
<div class="annotation" id="an2">And I'm another one!</div>
И я использую скрипт, подобный следующему:
function myAnnotation() {
var x = document.getElementById("an1");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
Как мне написать скрипт, который будет захватывать ID моих индивидуальных ссылок и затем открывать соответствующую аннотацию?