Earth
Earth

Reputation: 3571

How to insert one div into another div in Jquery Dialog

Code for parent-div dialog:

                $("#parent-div").dialog({
                    title: 'Parent',
                    width: parseInt(100, 100),
                    height: parseInt(190, 10),
                    modal: true,
                    buttons: [
                                {
                                    text: "Cancel",
                                    click: function () {
                                        $(this).dialog("close");
                                    }
                                },
                                {
                                    text: "Save",
                                    click: function () {
                                        $(this).dialog("close");
                                    }
                                }
                    ]
                });

Code for child-div dialog:

<div id="child-div"></div>

How to insert child div into parent div in Jquery Dialog along with buttons save and cancel which are already added ?

Upvotes: 0

Views: 4424

Answers (3)

Praveen
Praveen

Reputation: 56509

Try using appendChild() in javascript.

var childDiv = document.getElementById("child-div");
document.getElementById("parent-div").appendChild(childDiv);

Check this JSFiddle

Upvotes: 1

karthi
karthi

Reputation: 887

You can try the following:

$('#child-div').appendTo('#parent-div');

Upvotes: 2

Sean
Sean

Reputation: 4515

$("#parent-div").append($("#child-div"));

or if you want child-div to be the first element

$("#parent-div").prepend($("#child-div"));

You could string this together with your dialog call like so:

$("#parent-div").dialog({
    // your options
}).append($("#child-div"));

Upvotes: 2

Related Questions