views:

72

answers:

4

I'm using the .load() function to load a section of html that has some jQuery functionality that is bound to a certain class. =/

thoughts?

A: 

You have to manually bind the events after you set the html.

$.post('ajax/test.html', function(data) {
  $('.result').html(data);
  $('.result a').click(function() {
    alert('click');
  });
});

Additionally you can use live to help with it.

Dmytrii Nagirniak
this doesnt work as I had hoped
codeninja
Provide the HTML, AJAX resposne and JavaScript so we can see what exactly is not working.
Dmytrii Nagirniak
+2  A: 

You need to use JQuery's live function. This allows you to:

Attach a handler to the event for all elements which match the current selector, now or in the future.

Keltex
how do you use it? I havent had much success with live
codeninja
+3  A: 

Use live events:

$('.className').live(function(event) {
   ...
}

jQuery keeps a repository of all live selectors such as .className in this case. And it adds a handler to the document to listen for events that bubble up to the document. This special handler then basically runs through all the live selectors and forwards the event to those elements that match the live selectors, if any.

If any of the intermediate event handlers intercept the event and stop it from further propagating before it reaches up to the document, the live handlers will not be executed.

Anurag
A: 

If you are using a click event this will be your syntax:

   $('a.myClass').live("click", function() {

        // do something here

    });
Montana Flynn