0
Business problem: I’ll create a system that will run on a server-less platform. It can be a local administration area interface (a client for a service), or a mobile app. The application will load content dynamically, for easy updating and maintenance, using only client-side technology (CSS and javascript). Reasons do not come to the point not to pollute the topic.
Technical problem: The Document.write() object has a bad reputation for overwriting the document, and building every document with the write function is very complicated. So we usually choose to update content by getElementById, although many people recommend using AJAX or Jquery that for certain reasons do not work outside the server, for the scope of this project. However, getElementById does not load without calling a function in the code below, or even calling onload in Body:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="recebeProduto1"></div>
<script type="text/javascript">
getElementById("recebeProduto1").innerHTML = "teste";
</script>
</body>
</html>
Question: How and why getElementById does not load the page?
or
What alternatives to load content dynamically using Client-Side technology?
Boy, it really is
document.getElementById
....– Douglas Garrido
the idea is to explain why to avoid misunderstandings with javascript object, but yes! It is correct!
– Paulo Sérgio Duff
The method
getElementById
belongs to the object/classdocument
, so there’s no way to access it directly, only throughdocument
.– Douglas Garrido
However, when we call through a function, it makes content available. Because this?
– Paulo Sérgio Duff
When used within a function, the
getElementById
is within the context ofdocument
, however, it is always recommended to use thedocument
, thus avoiding errors such as "function not found".– Douglas Garrido
I have here the links related to this type of problem. Do you want to create a formal answer so I can mark as the best answer? https://www.w3.org/TR/DOM-Level-2-Core/core.html (getElementById introduced in DOM Level 2) https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById https://www.schools.com/jsref_obj_document.asp
– Paulo Sérgio Duff
No, it’s okay. The important thing is that you understand.
– Douglas Garrido