Bronzato
Bronzato

Reputation: 9362

Nothing is loaded into my jQuery dialog

Before I had the following jQuery:

var dialogDiv = "<div id='" + dialogId + "'></div>";

$(dialogDiv).load(href, function () {
    ...

It worked fine.

Now I changed a little bit like this:

var dialogDiv = "<div id='" + dialogId + "' class='modal hide fade'><div class='modal-body'><p class='body'></p></div></div>";

$('.modal-body p.body').load(href, function () {
    ...

Now nothing is loaded into my jQuery dialog. Any idea?

Thanks.

Upvotes: 1

Views: 87

Answers (3)

mamoo
mamoo

Reputation: 8166

You're trying to get an element which is not yet available in the DOM tree, you can either inject it before calling load() or wrap it into a jQuery object before loading content:

var dialogDiv = $("<div id='" + dialogId + "' class='modal hide fade'><div class='modal-body'><p class='body'></p></div></div>");

$('.modal-body p.body', dialogDiv).load(href, function () { ... }

Upvotes: 0

elclanrs
elclanrs

Reputation: 94131

The problem is that those elements don't exist in the DOM yet. Wrap it in a jQuery object:

var $dialogDiv = $("<div id='" + dialogId + "' class='modal hide fade'><div class='modal-body'><p class='body'></p></div></div>");

$dialogDiv.find('.modal-body p.body').load(href, function () {

EDIT: Eventually you'll have to insert that object in the DOM. You can chain insertAfter($bla) to the load() event.

Upvotes: 3

Aleksandrenko
Aleksandrenko

Reputation: 3063

Does class 'hide' shows the dialog div? If true the target element is not visible ;)

Upvotes: 0

Related Questions