开发者

where do the jqueryUI dialogs go after making them dialogs from divs

if you run this simple html, you'll notice that removing the html of the main div doesn't remove the child which was made dialog()

<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
<link type="text/css" rel="stylesheet"  href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/cupertino/jquery-ui.css"/>
</head>
<body class="ui-widget-content">

<script type="text/javascript">
    $(function(){
        $("#refill").click(function(){
        var x = $("#main").html();
        $('开发者_如何学编程.foo').dialog();
        $("#main").html("hello<div class='foo'>foo content</div>");
        alert($('.foo').length);
        });
    });
</script>
<a href="#" id="refill">refill</a>
<div id="main">
hello<div class="foo">foo content</div>
</div>
</body>
</html>

is it possible to remove the ex-children (i guess) of the main div without knowing their id, where are those divs ?


That's because dialog is not in the #main div anymore (inspect html through firebug after click). The common problem with jquery plugins (and jqueryui especially) is that they insert content right in body tag (before its closing part).

Your best option is, probably, to remove dialog through jqueryui API (destroy method). Or you can remove it by class .ui-dialog, if you're not afraid of collateral damage (other possible dialogs getting removed too).

edit
Ok, can't think of anything except removing dialog by hands. For example, this works for me

$('.foo').dialog('destroy');
$('body > .foo').remove();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜