Jaso2970 Jaso2970 - 1 year ago 92
jQuery Question

How replace text of an element which is loaded with ajax?

I need to replace (with jquery) the text for an element which is not loaded on document.ready. The element is loaded with ajax.

I tried with:

$('#my-div label').live({
var text = $(this).text();
$(this).text(text.replace('text', 'my text'));


the html is something like

<div id="my-div"><label>text</label></div>

Answer Source

Try this...

$(document).ajaxComplete(function() {
    var $label = $("#my-div label");
    var text = $label.text();
    $label.text(text.replace("text", "my text")); 

That will fire that function every time an ajax call is completed. That's ANY ajax call on that page.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download