I’m a noob and apparently a complete idiot. Here’s my very-stripped-down HTML:
<html>
<head>
<script type=’text/javascript’ src=’script.js’></script>
</head>
</html>
Now here is my very-stripped-down javascript:
window.onload = init;
function init() {
var allTags = document.getElementsByTagName(“*”);
document.write(allTags.length);
document.write(allTags.length);
}
Here is what I get in my browser:
43
From what I can tell, there should be 3 tags: <html><head><script>. There’s nothing more on the page. The first output it writes is “4”. How is it counting 4 tags when there are only 3? Secondly, I ask it to output the same thing again, and it gives the answer of “3”. Why is the length of allTags changing from 4 to 3 with nothing else being down in the script? I’ve also tried adding tags in the HTML. It makes the first number go up, but the second output is always three? I have no idea what’s going on here. Any ideas?