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.
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")
});
$.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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With