I am using jQuery Dialog to load other pages into a dialog on the main page. The other pages may have anchor tags, and I am using the completed event of the load function to select all of the anchor tags in the div into which the content was loaded. I then wire up the anchor tags click event handler so that the content is loaded into the div which is contained on the main page. This works, however only twice. When you run the sample code below, Partial1 appears in the dialog. When I click on the Partial2 link in the dialog, Partial1 is loaded into the dialog, however, this time when I click on the Partial2 link, it loads in the main page. What am I doing wrong and/or failing to grasp?
Home/Index:
<a href="/Home/Partial1" id="help">Partial 1</a>
<div id="dialog" style="display: none">
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#help").click(function () {
adjustNestedAnchors($(this));
$("#dialog").dialog().show();
return false;
});
function adjustNestedAnchors(element) {
$("#dialog").load($(element).attr("href"),
function (response, status, xhr) {
if (status != "error") {
$("#dialog a").click(function () {
$("#dialog").load($(this).attr("href"), adjustNestedAnchors($(this)));
return false;
});
}
});
}
});
</script>
Home/Partial1
This is a sample partial view, which has a link back to <a href="/Home/Partial2">Partial2</a>.
Home/Partial2
This is a sample partial view, which has a link back to <a href="/Home/Partial1">Partial1</a>.