Smruti Ranjan Sahoo
Smruti Ranjan Sahoo

Reputation: 254

The controls cloned in jQuery gets erased on page load

I have a button(Button1) in a div element. Another button(Button2) outside that div may be in another div, on click of Button2 the other div gets cloned using jQuery "clone()" method. Each time i click on the button(Button2) the new div element with the button gets cloned with all its events.

Example :

$(function () {
        $("#Button1").click(function () {
            $("#divHello").clone(true).appendTo("#divBye");
        });
    });

The Button1 is attached with event Click to write its ID to the page. But the problem is that on click of Button2 the with Button1 get clonned as many times the button clicked but when the Button2 is clicked altheough it writes the ID to page but all other clonned div elements get erased which should not be as per my requirement.

If any one is having solution for it please help.

Upvotes: 0

Views: 127

Answers (1)

Sam
Sam

Reputation: 15770

Right! You are creating elements on the client side, when you reload the page, the server sends back what it has, that does not include the elements you created on the client.

Upvotes: 1

Related Questions