"append" event on page load

Asked

Viewed 67 times

1

In this code section, the div1 is positioned in the div2 when you click on it, but I wanted it to be done automatically when loading the page without having to click on it.

I have tried replacing the event . click by . load or . ready but it does not give.

jQuery(function ($) {

    $('#DIV1').click(function () {

        $('#DIV2').append(this);

    });  
});

1 answer

1


Must do so:

jQuery(function ($) {
    $('#DIV2').append($('#DIV1'));
});

In the code I had, this was a pointer to the clicked element, ie $('#DIV1'). And when the click appeared the div2 received by append the this.

  • 1

    Man, thank you so much. I broke my head so much with this already. Working right!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.