Removing a DOM element from an element that is created by an external script

Inside the page, I have third-party ad content that is generated by an external script. This content takes a little time to download. I would like to remove a line break from the advertising content - to do this, wait until the external script loads, and all the functions called inside this script stop working. I was looking for the following idea, but I think it only waits for the external script to load:

$.getScript( "http://www.external_site.com/widget.js").done( function(data, textStatus, jqxhr) {
     $('.result').find('br').remove();  
});

What is the best way to wait for an external script to do all its DOM manipulations before calling the .remove () function?

+4
source share
1 answer

, -, onreadystatechange load, <script>, JavaScript.

() , :

// listening for the onreadystatechange and/or load
// events fired from the newly-added "script" elements:
$('script').on('onreadystatechange load', function (e) {
    // performs the following simple/contrived functionality:
    $('body').find('br').remove();
});

JS Fiddle demo.

:

+5

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


All Articles