Dr. Dre
Dr. Dre

Reputation: 149

Use .html() to fill out a div created through an Ajax request

I would like to fill out a div created through an AJAX request using jQuery.

It seems that I can't do it since my new DIV isn't in the DOM at the time I bind the event. Here is my code:

function updateNotice(content, type) {
    noticeName.html(content).addClass(type).show("slow");
}

noticeName is set to $( "#form-notice" ); in a global variable. But form-notice is a div that is sent from another ajax request (called before the one above), how can I fill it? Should I use jQuery.on()? How to use it?

Upvotes: 0

Views: 806

Answers (1)

mimo
mimo

Reputation: 937

You need to do this $( "#form-notice" ); after the html you get from your ajax call is rendered.

function updateNotice(content, type) {
noticeName = $( "#form-notice" );
noticeName.html(content).addClass(type).show("slow");
}

Upvotes: 2

Related Questions