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

Popular posts from this blog

c++ - Cmake produces file extensions in static library archives -

c# - Roxy file manager in MVC doesn't accept session path -

c# - Check if a NumericUpDown has no value -