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?
28 Replies
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
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
So hold on...
console.log(test)
returns the nodeList with a length
of 1
console.log(test.length)
returns 0
Either I am completely stupid or there is smth weird going onUPDATE using getElementsByClassName gives same result.........................................................................................................
why is it not allowing me to grab it wtf? This is actually frustrating me
can you share a codepen? cause it works for me
well um, could you first try n explain this to me while I get a codepen on it
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
on a querySelectorAll it just shows nothing xd
ANyway, the codepen will be here shortly
it works just fine for me in my test:
with this:
It will take a lil bit longer, codepen doesnt take my login anymore
works too
The login is locked, nice...
well, I don't get why its not working for me, its so confusing
share all your HTML and JS code in codeblocks then?
not in screenshots
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 ?
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?
What exactly do you mean ?
If you mean fontawesome
I am using fontawesome yes
I haven't used it in forever, do you load JS or just CSS for that?
but in other projects I am able to jsut call upon them
even tho they are also fontawesome icons
the top one is the fontawesome
the bottom one is my script
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
i sorta forgot
how tos end my pen xd do i just send the link
its been ages since i been on pen
you click save, then when the URL has a unique string in it you send that link
also, if I use fontawesome in the html (gearpanel) head information
it also just works fine
there's no
defer
on your script tag
it runs before the DOM is fully loaded
add defer
to your own script tag'-' 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
no worries, glad we found the cause!
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