I'm currently working on a project where I can't change the HTML file, but I have to write some JavaScript to add features to the website. The website puts the tag at the top of the file in the head next to the Title and the rest of the HTML file is stored in the body right below.
<head>
...
<script src="./index.js" type="text/javascript"></script>
</head>
<body>
<section class = "row mt-3">
...
</body>
Here's an example of what it looks like with some of the lines missing. I'm trying to put the function into my js folder and running this to test if it's working (there are multiple td tags in ), yet I get and HTMLCollection with 0 items in it.
(function(){
debugger;
var tbody = document.getElementsByTagName('td');
console.log(tbody.length);
})();
Is there something wrong with my code? Does it matter if is before any HTML is actually written?
I've tried doing multiple different tag names to no avail, but have been successful in obtaining items in the HTMLCollection when I use the inspector and run the documents.getElementsByTagName('td'); which makes me wonder what the problem really is.