Lukas
Lukas

Reputation: 7734

Do something after div loads with jquery

i have some problem with my jquery. I need to remove first two elements from some list after specify div loads. When document is ready I didn't have this div in my DOM, it's appending after some click action. So, what i need to do is make function which this specify div will be adding to my DOM. This is my code, thx for help.

setTimeout(function(){
    if ($('.sv_flex_slider .slides').find('li').size() > 3) {
        $('#fancybox-thumbs').load(function(){
            setTimeout(function(){
                $('#fancybox-thumbs ul').find('li').eq(1).remove();
                $('#fancybox-thumbs ul').find('li').eq(2).remove();    
            },200);
        })
    }
},200);

Upvotes: 2

Views: 2275

Answers (1)

tbleckert
tbleckert

Reputation: 3803

You need a trigger when the div is created. Like this:

$('#some_element').on('click', function () {
    var $element = $(document.createElement('div')).attr('id', 'newDiv');
    $element.trigger('created');    
});

Then you can listen to that:

$('body').on('created', '#newDiv'....

Upvotes: 3

Related Questions