I have the following in jQuery mobile:

```
<script type="text/javascript">
    $("#locate_results").live("pageinit", function(event) {
        $("#venues li a").click(function(e) {
            e.preventDefault();
            // Update location
            $(".ui-dialog").each(function() { $(this).dialog("close"); });
        });
    });
</script>

<div data-role="page">
    <div data-role="header">My Form</div>
    <div data-role="content">
        ... other content ...
        <a href="#locator" data-rel="dialog">Choose a Location</a>
    </div>
</div>
<div data-role="dialog" id="locator">
    <div data-role="header">Search for a Location</div>
    <div data-role="content">
        <form action="/locate" method="post" data-rel="dialog">
            <input type="text" name="query" />
            <input type="submit" value="Search" />
        </form>
    </div>
</div>

```

The output of /locate is as follows:

```
<div id="locate_results" data-role="dialog">
    <div data-role="header">Search Results</div>
    <div data-role="content">
        <ul id="venues" data-role="listview">
            <li><a href="#">Venue 1 Name</a></li>
            ... more results ...
        </ul>
    </div>
</div>

```

So essentially, 

1. User clicks the "Add a Location" link.
2. Location search form is loaded in a dialog
3. Search results loaded in a second dialog
4. User clicks a search result in the second dialog.

Step 5 should be both dialogs closing, returning the user to the original page content. However only the topmost dialog (#locate\_results) closes. I have also tried the following and gotten the same result:

```
$("#locate_results").dialog("close");
$("#locator").dialog("close");

```

and

```
$(".ui-dialog").dialog("close");

```

I've tried following these answers, with no luck:

* [close multiple jquery ui dialogs at once](https://stackoverflow.com/questions/3742277/close-multiple-jquery-ui-dialogs-at-once)

What would be the correct way to close all open dialogs in jQuery Mobile?

jsFiddle demonstrating the issue:

<http://jsfiddle.net/zUuSy/>