简体   繁体   中英

To append dynamic paragraph in dynamic div

I had created a dynamic div and paragraph in dialog box to show confirmation while submitting the form. How to append the dynamic paragraph inside the dynamic div, Please help me on this.

Thanks in Advance.

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Jquery Confirm Dialog</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
        <script src="JQUERY/jquery-ui.js"></script>
        <style type="text/css">
                .ui-dialog .ui-dialog-titlebar, .ui-dialog .ui-dialog-buttonpane { font-size: 0.8em; }
        </style>
        <script type="text/javascript">
            $(document).ready(function ()
            {
                $("#ShowDivPopup").click(function ()
                {
                    var DynamicDiv = $('<div id="dynamicPopupDiv" style="width: 340px;height: 380px;background-color:#fff;display: none"></div>');
                    var Message = $('<p>Are you Sure</p>');

                    $('body').append(DynamicDiv);
                    $('#DynamicDiv').append(Message);
                    $("#dynamicPopupDiv").dialog(
                    {
                        modal: true,
                        height: 180,
                        width: 320,
                        title: 'Info',
                        closeOnEscape: false,
                        resizable: false,
                        draggable: true,
                        buttons: {
                            "Ok": function ()
                            {
                                alert("Submit form ");

                            },
                            "Cancel": function ()
                            {
                                $(this).dialog('close');
                            }
                        }
                    });
                });
            });

        </script>   
    </head>
    <body>
        <form id="myForm" method="post" action="return welcome()">
            <div id="ConFirmDiv" style="width: 340px;height: 380px;background-color:#fff;display: none">
                <span>Are You Sure Want to Submit</span>
            </div>
            <input type="button" id="ShowDivPopup" value="Show Popup" />
       </form>
    </body>
</html>

You want to refer to the DynamicDiv object not the literal:

$(DynamicDiv).append(Message);

or:

$("#dynamicPopupDiv").append(Message);

You called your ID dynamicPopDiv, therefore when you reference $("#DynamicDiv") it doesn't return the jQuery object.

var DynamicDiv = $('<div id="dynamicPopupDiv" style="width: 340px;height: 380px;background-color:#fff;display: none"></div>');
var Message = $('<p>Are you Sure</p>');

DynamicDiv.append(Message)
$('body').append(DynamicDiv);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM