Equivalent to window.onload after changing the DOM?

When the first page loads, we can use window.onloadit to make sure all resources are loaded before we do anything.

My question is: if we change the DOM (for example, by inserting some html based on the ajax request), is there any event that will fire when the document is loaded again? (for example, when the inserted html contains multiple images).

(The solution with jQuery will be fine).

+5
source share
3 answers

Short answer: NO.

: , , (https://developer.mozilla.org/en-US/docs/DOM/MutationObserver). , .

BTW, document.ready , ( ) . , dom ( , (, , javascript) ).

+2

.done().

: , .

jQuery See Here

0

( , . )

You can find the testcase here: http://maakmenietgek.nl/testcases/domready/ Note that I cannot get it to work in the fiddle, so the stand-alone test file

index.html looks like this:

<!DOCTYPE html>
<head>
  <title>Testcase</title>
  <script src="jquery-1.8.2.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      $('#clickme').click(function() {
        $.get('ajaxdata.html', function(data) {
            $('#addhere').html(data);
        });
      });
    })
  </script>
</head>
<body>
  <p id="clickme">clickme</p>
  <div id="addhere">
  </div>
</body>
</html>

The data loaded by the call $.getis as follows:

<p>added data</p>
<script type="text/javascript">
    $(document).ready(function() {
        alert('added data');
    });
</script>

Warning appears after adding html to DOM

0
source

All Articles