0

I'm facing a issue getting dynamically loaded elements in the dom that I cannot find the right answer to solve this issue.

Let's say I have an MVC architecture where I load all my views into a container div.

So I load a view which also has a ul element, now I create multiples li dynamically and when I call.

 ul = document.getElementById("idelement");

I get undefined, even if the view is already loaded.

I tried using, (document).ready, event delegation on(load), among other techniques and I cannot find the rigth solution for this.

Any advices?

apxcode
  • 7,696
  • 7
  • 30
  • 41
andresmijares
  • 3,658
  • 4
  • 34
  • 40
  • 3
    If `document.getElementById` can't find it, it is not in your DOM. – Alex W May 16 '14 at 19:25
  • do you have a callback for when all your dom is loaded? – Evan May 16 '14 at 19:26
  • it is in there, cause I can see it on the inspector and it is perfectly loaded. And no, I do not have a callback, however the element inside the view which are not dynamically loaded display perfectly – andresmijares May 16 '14 at 19:28
  • Can you demonstrate this problem with a ([minimal](http://stackoverflow.com/help/mcve)) live [JS Fiddle](http://jsfiddle.net/), or similar, demo? – David Thomas May 16 '14 at 19:29
  • sadly, I cannot, there is a lot of code to display. – andresmijares May 16 '14 at 19:30
  • but is it perfectly loaded when your code executes? Sure sounds like it isn't – charlietfl May 16 '14 at 19:34
  • Hence 'minimal,' reduce your problem to the *simplest*, *smallest* demonstration of the problem (without the accompanying cruft). If you can't do that, then I'm unsure how we can help. – David Thomas May 16 '14 at 19:35
  • well it is, it does not drop any errors, and I only cannot see the dynamic elements, however if I console.log the variables that supposes to add the elements, it display the right element, it is just not inserting them – andresmijares May 16 '14 at 19:39

1 Answers1

0

Finally, I came out with this article , it looks like a chrome bug, the solution I found was to set a timeout of 500ms as the article says.

Community
  • 1
  • 1
andresmijares
  • 3,658
  • 4
  • 34
  • 40