views:

189

answers:

1

I have a div which is being populated through curl from another html page .Now the data is populating correctly but i want to use jquery or javascript on the ids or classess of the fetched data. I tried using livequery ,binding but of no use. Can you please help me .

A: 

Are you wrapping your javascript with $(document).ready(function() { } ); as to ensure the dom is fully loaded?

For instance:

$(document).ready(function() { $('#id').click(function() { // do stuff } ); }

This would fix the issue if the HTML fetched via CURL is being populated via a direct post-back. If you're populating the data asynchronously, then you'll either have to use the .live() mechanism for binding (through read the docs carefully, live() doesn't work in certain scenarios and was added in the most recent version of jQuery -- so check that you've got the right version of jQuery and that you're not trying to use events that aren't supported with that binding mechanism). Furthermore, live is a bit of performance tax, so I'd do something like.

$.ajax({ // Lots of ommitted options for simplicity's sake 
          success: function(data, status) { 
               $('#targetDiv').append(data);
               $('#targetDiv #elementID').click(function() { // do stuff });
          }
        });

Hopefully this helps steer you in the right direction. With a code sample we could certainly help more.

Skone