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

asp.net - Procedure or function "Procedure name" expects a parameter "Param name" which was not supplied occurs rarely -

jsp - No mapping found for HTTP request with URI with annotation config Spring MVC and Jetty -

sql server ce - Is there some way to make sqlce3.5 and 4.0 co-exist in the C# project -