Rouge
Rouge

Reputation: 4239

How to detect if the elements are loaded dynamically.

I am trying to check if the elements that are loaded dynamically have complete loaded.

I want the user to click the button -> load elements -> check if the elements are loaded.

I have

<button id='click'>click</button>


//create and append div..
$('#click').click(function(){

   var div= $('<div>').attr('id','testDiv').addClass('div');

   $('body').append(div);

})


//detect when the div is loaded...
$('#testDiv').load(function(){
    console.log('load test div')

})

How do I get 'load test div' show in the console.... thanks a lot!

Upvotes: 0

Views: 127

Answers (1)

Musa
Musa

Reputation: 97717

Elements aren't loaded, when you add them to the dom they are there. So right after $('body').append(div); the div is in the dom.

Upvotes: 2

Related Questions