javascript - How to get id of the element correctly? -
I try to get the element that is "div", but I get a type of error in Firefox , What is the reason for this?
& lt; Script type = "text / javascript" & gt; Window.onload = function () {var oParent = document.getElementsByTagName ('div') [0]; Console.log (oParent); Var arr = oParent.getElementById ('div'); Console.log (arrive); } & Lt; / Script & gt; & Lt; Div class = "test" & gt; & Lt; Div & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; / Div & gt; & Lt; Div id = "div" & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; / Div & gt;
you should replace
var arr = oParent.getElementById ('div');
with
var arr = document.getElementById ('div');
That's because getElementById
is a method of a document
and not divs.
Comments
Post a Comment