This question already has an answer here:

I'm trying to change inner HTML in loaded div by this function:

$("#container").load("site.php");

In site.php I have <div class="users_count"> and I would like to put some text inside it. I'm trying to use $(".users_count").html("TEST") but it can't be done since jQuery do not see .users_count class.

I've heared about jQuery on() and live() but it requires some event like click, keyup etc...

I need to put some text in this div without any event - just do it in my function without user action.

share|improve this question

marked as duplicate by Gothdo javascript 1 hour ago

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
please post your complete code here – Blueblazer172 10 hours ago
    
Next time please search before asking such a basic question. Similar questions have already been asked many times and we don't need even more duplicate questions. – Gothdo 1 hour ago

You could use the complete callback of load() :

If a "complete" callback is provided, it is executed after post-processing and HTML insertion has been performed.

$("#container").load("site.php", function() {
    $(".users_count").html("TEST")
});

Hope this helps.

share|improve this answer
1  
Similar questions have already been asked many times (you can find some by searching "jquery access loaded element"). Instead of answering it, you should find a good duplicate target and close this question. – Gothdo 1 hour ago

$.fn.load() is async, you could use complete callback:

$("#container").load("site.php", function(){
  $(this).find('.users_count').html('TEST');
});

$(this).find('.users_count') isntead of just $('.users_count') because it is better to set relevant context, you wouldn't want in most cases target elements not descendant of loaded content, depending selector used. In your case it would change nothing but sometimes who knows...

share|improve this answer
1  
Similar questions have already been asked many times (you can find some by searching "jquery access loaded element"). Instead of answering it, you should find a good duplicate target and close this question. – Gothdo 1 hour ago

You want to do stuff when the loading is complete. This is done in the complete callback.

$( "#result" ).load( "ajax/test.html", function() {
  alert( "Load was performed." );
  // Do your stuff here
});
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.