Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery/javascript check if the div finished loading?

I have a facebook like button on my website like that:

<div class="fb-like" data-href="https://www.facebook.com/xxx"
             data-send="false" data-width="300" 
             data-show-faces="true">
</div>

I want to use jQuery or java script to check if this div is 100% finished loading on the page and then do other stuff.

I used $(document).ready and .load to check but non of them worked (they do the function even before the div finished loading). Does this problem have to do anything with the fact that this div contain an iframe from another website ? what am I doing wrong here ?

UPDATE I just tried this and it did not work at all:

$(document).ready(function() {
    $(".fb-like").load(function (){
         alert("Loaded :)");
    });
});
like image 787
Max Pain Avatar asked Jan 07 '13 08:01

Max Pain


2 Answers

I believe the issue is that you need to test if the iframe is loaded rather than the div. I would suggest changing your selector to include the child iframe and checking for the load event on this.

$('.fb-like iframe').load(function() {
  console.log('iframe loaded');
});
like image 121
Undefined Avatar answered Sep 18 '22 23:09

Undefined


$('.fb-like iframe').on(function() {
  console.log('iframe loaded');
 });
like image 20
Zeal Murapa Avatar answered Sep 21 '22 23:09

Zeal Murapa