2

The following simply loads a jquery-ui dialog from an external html file.

$('#showdialog').click(function(e) {
    var div = $('<div>loading...</div>');
    div.dialog({
        modal: true,
        open: function() { div.load('anotherpage.html'); }
    });
    e.preventDefault();
});

After the DOM loads from the external html file, I'd like to interrogate it with JQuery. For example, supposing anothorpage.html had a bunch of anchors on it, I'd like to wire up click handlers for them when it loads into the dialog.

Any ideas?

2 Answers 2

3

You can define more then one parameter of jQuery.load (see http://api.jquery.com/load/) so after load is done you can do something:

div.load('anotherpage.html', function() {
  alert('Load was performed.');
});

place code which you need instead of alert.

Sign up to request clarification or add additional context in comments.

Comments

1

Look into using .live() or .delegate(), which will allow you to attach handlers to events on elements within the dynamically loaded content.

For example:

$(document).ready( function() {
    $('div.yourDynamicContainer a').live('click', function() {
        doSomething()
    })
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.