Call javascript function after loading div

How to call javascript function after loading a specific div?

+3
source share
2 answers

Typically, JavaScript execution is delayed until the entire document is loaded using an event window.onload.

window.onload = function() {
    // Do stuff
};

Otherwise, if you do not want this or you do not need to wait for the entire document to load, you can enable your JavaScript immediately after the closing element ( div) tag that interests you.

<div>
  ...
</div>
<script src="blah-blah-blah.js"></script>
+4
source

I would check if div exists in DOM: Javascript

 if(document.getElementById('myDiv'))

or jQuery

if($("#myDiv"))

+1
source

Source: https://habr.com/ru/post/1739571/


All Articles