JavaScript querySelect & document.getBy issues

Usually I have no issues with it, but right now, I'm being stumped by this and cant figure out what on earth is happening here (see image) So, the getElementsByName returns a nodeList witha length of 1, so basically index0 yet calling upon [0] is undefined? and calling it by querySelector (it literally works in the css with [name=input_The-name] returns a null? what?
No description
28 Replies
Brightie
Brightie12mo ago
If anyone can bring some light as to what's going on or what I'm doing wrong, please enlighten me bc I'm literally stumped by this Here is the html object Im trying to grab btw
No description
Brightie
Brightie12mo ago
I mean I know I can use some other stuff like grabbing by a class for the + but I'd prefer to grab it by name so I'll never have to shuffle with childcounting and editing when more + icons would bep laced
Brightie
Brightie12mo ago
So hold on... console.log(test) returns the nodeList with a lengthof 1 console.log(test.length) returns 0 Either I am completely stupid or there is smth weird going on
No description
Brightie
Brightie12mo ago
UPDATE using getElementsByClassName gives same result......................................................................................................... why is it not allowing me to grab it wtf? This is actually frustrating me
Jochem
Jochem12mo ago
can you share a codepen? cause it works for me
Brightie
Brightie12mo ago
well um, could you first try n explain this to me while I get a codepen on it
No description
Jochem
Jochem12mo ago
I can't directly, other than .forEach, hence the request for the codepen .forEach is an array method, it doesn't exist on a HTMLCollection
Brightie
Brightie12mo ago
on a querySelectorAll it just shows nothing xd ANyway, the codepen will be here shortly
Jochem
Jochem12mo ago
it works just fine for me in my test:
No description
Jochem
Jochem12mo ago
with this:
<i>hello world</i>
<i>hello world</i>
Brightie
Brightie12mo ago
It will take a lil bit longer, codepen doesnt take my login anymore
Jochem
Jochem12mo ago
works too
No description
Brightie
Brightie12mo ago
The login is locked, nice... well, I don't get why its not working for me, its so confusing
Jochem
Jochem12mo ago
share all your HTML and JS code in codeblocks then? not in screenshots
Brightie
Brightie12mo ago
I don't get it.... On codepen the js does what its supposed to, but if I open the index.html file itself it doesn't ?
Jochem
Jochem12mo ago
could it be running javascript that changes the DOM from what's in your HTML? a script that's replacing the i tags with actual icons for example?
Brightie
Brightie12mo ago
What exactly do you mean ? If you mean fontawesome I am using fontawesome yes
Jochem
Jochem12mo ago
I haven't used it in forever, do you load JS or just CSS for that?
Brightie
Brightie12mo ago
but in other projects I am able to jsut call upon them even tho they are also fontawesome icons
<script
src="https://kit.fontawesome.com/8d43e0b763.js"
crossorigin="anonymous"
></script>
<script src="./assets/scripts/script.js"></script>
<script
src="https://kit.fontawesome.com/8d43e0b763.js"
crossorigin="anonymous"
></script>
<script src="./assets/scripts/script.js"></script>
the top one is the fontawesome the bottom one is my script
Jochem
Jochem12mo ago
without seeing the issue in my own browser, I can't diagnose it you should be able to include FA in codepen too, using the gear icon for the JS panel
Brightie
Brightie12mo ago
i sorta forgot how tos end my pen xd do i just send the link its been ages since i been on pen
Jochem
Jochem12mo ago
you click save, then when the URL has a unique string in it you send that link
Brightie
Brightie12mo ago
also, if I use fontawesome in the html (gearpanel) head information it also just works fine
Jochem
Jochem12mo ago
there's no defer on your script tag it runs before the DOM is fully loaded add defer to your own script tag
Brightie
Brightie12mo ago
'-' I am actually mad at myself Usually I alwasy put the defer the one time I don't... Right okay thanks xd so I wasn't going crazy I was just stupid thanks! Id probs been scratching my head as to why it kept on failing me , thought i was going crazy
Jochem
Jochem12mo ago
no worries, glad we found the cause!
Brightie
Brightie12mo ago
oh, I get why it happened... I added it using the autofill from one of my addons and it didn't put defer and I didn't think of manually putting it Brainfart moment
Want results from more Discord servers?
Add your server