So far I have tried this, but it is not working. If I change the footer to div in this Line var x = document.getElementsByTagName("footer"); than it show all the div in my code,I also do not want this.
Can anyone help me by telling what is wrong in this code and how to make this code working ?
HTML
<p> name:</p> <div> john</div>
<p> class: </p> <div> English</div>
<p> email: </p> <div> [email protected]</div>
<footer>
<button onclick="show()">Contact</button>
<p id="first"></p>
<p id="second"></p>
<p id="third"></p>
</footer>
JS
function show() {
var x = document.getElementsByTagName("footer");
document.getElementById("first").innerHTML =
'first div: ' + x[0].innerHTML;
document.getElementById("second").innerHTML =
'second div: ' + x[1].innerHTML;
document.getElementById("third").innerHTML =
'third div: ' + x[2].innerHTML;
}
classoridto your divs? Otherwise all divs will be returned using this code -document.getElementsByTagName("div");