Newbie: how do I analyse DOM Objects?
-
I'm learning Javascript. I'm following some example code on a video. I've got stuck trying to change some existing code. The first step I thought would be to identify the object I'm dealing with. What's the best way of doing this? I've tried console.dir(document) - but that bring back *everything*. I know I can drill down further... but I thought I'd ask here before trying anything else. Thanks.
-
I'm learning Javascript. I'm following some example code on a video. I've got stuck trying to change some existing code. The first step I thought would be to identify the object I'm dealing with. What's the best way of doing this? I've tried console.dir(document) - but that bring back *everything*. I know I can drill down further... but I thought I'd ask here before trying anything else. Thanks.
-
I am not quite certain what you are asking, but take a look at XML DOM Tutorial[^].
Richard, thanks for the reply. I was stuck on a problem. I couldn't see what I was doing wrong. I had an ID and in my Javascript I had:
const CIRCLE = document.querySelector('circle');
I'd spent sooo much time trying to figure out what I had done wrong. So... in the end I thought there must be a way to find all objects/elements on a page? I had tried
document.querySelectorAll
but wasn't sure where to type this (complete newbie... learning JS). I found the error: I was missing a # But... I still have my question... how could I drill down and find a specific object that I was having trouble getting the exact details of? Hope that makes sense.
-
Richard, thanks for the reply. I was stuck on a problem. I couldn't see what I was doing wrong. I had an ID and in my Javascript I had:
const CIRCLE = document.querySelector('circle');
I'd spent sooo much time trying to figure out what I had done wrong. So... in the end I thought there must be a way to find all objects/elements on a page? I had tried
document.querySelectorAll
but wasn't sure where to type this (complete newbie... learning JS). I found the error: I was missing a # But... I still have my question... how could I drill down and find a specific object that I was having trouble getting the exact details of? Hope that makes sense.
-
Sorry, I am still not sure what you are trying to do, but see document.querySelectorAll() - Web APIs | MDN[^].
i think it's just me. :) i freaked out after spending hours trying to find where i had gone wrong. so was looking for a way to find all items on a page and then i could dig down and get the exact text i would need to put in for accessing. thanks for all ur replies.
-
i think it's just me. :) i freaked out after spending hours trying to find where i had gone wrong. so was looking for a way to find all items on a page and then i could dig down and get the exact text i would need to put in for accessing. thanks for all ur replies.
-
Richard, thanks for the reply. I was stuck on a problem. I couldn't see what I was doing wrong. I had an ID and in my Javascript I had:
const CIRCLE = document.querySelector('circle');
I'd spent sooo much time trying to figure out what I had done wrong. So... in the end I thought there must be a way to find all objects/elements on a page? I had tried
document.querySelectorAll
but wasn't sure where to type this (complete newbie... learning JS). I found the error: I was missing a # But... I still have my question... how could I drill down and find a specific object that I was having trouble getting the exact details of? Hope that makes sense.
If you want to access everything in the order it is stored in as HTML, use
document.querySelector("html")
to get the root html element of the document, and then use the
.children
array of any element to see what's inside it.