Reputation: 945
I'm trying to traverse the document DOM to obtain certain html elements, so I can invoke their eventListeners with JavaScript.
To this end, I know that the elements I'm looking for are contained in a certain html class (dc-chart). Hence I obtain the base elements by
x = document.getElementsByClassName("dc-chart")
Now, my goal is to, say, traverse the rect class elements inside the 7th element above:
How would I go about doing this?
x.[7].getElementById("stack _0")
doesn't seem to work in my Chrome webconsole; getElementById can't be chained to x[7].
Upvotes: 0
Views: 141
Reputation: 1876
"stack _0" is not an id, they are two classes separated by a blank space: "stack" and "_0".
And you should use getElementsByClassName()
instead of getElementById()
Upvotes: 2