$('.my_content_class a')
is the way to do it. What you are probably experiencing is that you run that function before the contents was loaded. AJAX is working asynchronously so your script doesn't end until the contents is loaded before proceeding to the next line of code. You should place your code in load
method callback so it's executed after AJAX requests completes his work.
var url = 'http://example.com/test.html';
var data = {var1: foo, var2: bar};
$('.my_content_class').load(url, data, function () {
// this will be executed after the content was successfully loaded
});
From what I can read in the docs callback is called once AJAX finishes its work and I'm not sure if this is after the actual contents was loaded to the DOM tree. You need to figure this out on your own and if it's done before that you have to create some small delay in callback function to launch after DOM was updated. setTimeout
may come handy for that but first I would make sure that you need that part.