Load element after dynamic parent div?

Coming back from this thread Select Parent DIV if i dont know the id?

I’m facing an issue that not sure if It’s possible to fix.
I have my element + script that loads after page load, but this only works when the element is placed in the index page. In the case, the element is placed in a hidden pop-up that turns visible when a button is pressed or X event happens, when the pop-up comes visible the element looks broken…

I think it’s because the element is loading before the parent div. So my idea is somehow to load-after the parent div element.
In the case, the element is placed in the index will work loading after the parent div (index) and in the case, the element is placed in a pop-up will load after that pop-up div.

I tried several methods but no luck on getting the right path to do (cause my pop-up div) is random and every time is different so can’t reference directly by id.

I tried things like this:

Any ideas?

Hi @Raiikou, inserAfter() is a function and doesn’t have a parentNode property… did you mean something like this?

// Inserts `myElement` after the parent of the `#upholder` element, where
// `myElement` is a selector or reference to the element in question

(Also note the “hashtag” for the ID selector, which you need if you don’t use getElementById() as in your other thread.)

1 Like

Yeah, but the problem is we need the myElement id/class .after(myElement)

The problem is that I don’t have the id/class of the popup div. Is there any way to refer to the nearest div?


Does div have something like: document.body ?
I.E: div.body


Something like closest()? But I have to say that I find your description a bit too abstract to really help you with actual code… do you think you can set up a very basic example that demonstrates the problem? You might give some elements classes like unknown-class or something to make clear which references you can get directly and which not…


No, but you can get its children like so:

// VanillaJS

// jQuery

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.