getElementById()
is on the document
object.
If I have an element reference already, how can I find the child (or children's child etc) that has a given ID?
var parent = document.getElementById(parentId),
child = parent.getElementById(childId);
This code fails because normal elements on a page do not have a getElementById
method.
(I'm in maintenance mode, IDs are not necessarily unique, and cannot use jQuery).
You could use querySelector()
:
child = parent.querySelector("#" + childId);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With