views:

40

answers:

1

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"&gt;&lt;/script&gt;
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"&gt;&lt;/script&gt;
<link type="text/css" rel="stylesheet"  href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/cupertino/jquery-ui.css"/&gt;
</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 ?

+1  A: 

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();
Nikita Rybak
the destroy doesn't help btw
Omu
@Omu From the docs for _destroy_: _"Remove the dialog functionality completely. This will return the element back to its pre-init state"_. Do you mean, this method fails at that?
Nikita Rybak
@Nikita Rybak yes, look here http://jsfiddle.net/P2CPC/
Omu
@Nikita Rybak about your edit, yes, that's what i'm currently doing, I delete them by id(i was using class just in the sample only); don't know if body > foo makes sense, cuz everything is in body anyways
Omu
@Omu 'a > b' means that 'b' is a direct child of 'a': http://api.jquery.com/child-selector/
Nikita Rybak