JQuery DOM DOM Dialog Query Dialog Box

The following just loads the 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 is loaded from the external html file, I would like to interrogate it using JQuery. For example, suppose anothorpage.html had a bunch of bindings, I would like to hook up click handlers for them when it loads into a dialog.

Any ideas?

+2


a source to share


2 answers


You can define more than one parameter jQuery.load

(see http://api.jquery.com/load/ ), so after the download is complete, you can do something:

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

      



enter the code you need instead alert

.

+3


a source


Look at using .live()

or .delegate()

, which will allow you to bind handlers to events on elements in dynamically loaded content.

For instance:



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

      

+1


a source







All Articles