I can set the text of a figcaption if I access it by its ID (Line commented out in code below). However I can’t set it if I access the figcaption as firstChild of the figure. Why not?
<body>
<figure id="fig1">
<figcaption id="figcap1">Camberley Mail</figcaption>
<button type="button" id="thumb1" onclick="showBigImg (1);"></button>
<p>Text to go with picture.</p>
</figure>
<script>
"use strict";
function showBigImg(figNum) {
// let temp = document.getElementById("figcap" + figNum);
let temp = document.getElementById("fig" + figNum).firstChild;
temp.innerHTML = "some text";
}
</script>
</body>
</html>