Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery dialog .html() question

I am using a jquery dialog and want to set the .html value with an external html file located on the same server. What I'm unsure of is exactly how to achieve this.

var $tos_dlg = $('<div></div>')
  .html($(this).load('/includes/tos.html'))
  .dialog({
    autoOpen: false,
    title: 'Policies &amp; Terms of Service',
    width: 600,
    height: 400,
    modal: true
});

The above section where the .html() is called is where I want to inject the contents of the external file. I think that the .load function would work somehow, but just not sure if that is the right approach and if so, how exactly to implement it. Can anyone help?

Thanks

like image 422
Skittles Avatar asked Dec 28 '22 17:12

Skittles


2 Answers

Call .load() on $tos_dlg directly:

var $tos_dlg = $('<div></div>')
    .load('/includes/tos.html')
    .dialog({
        autoOpen: false,
        title: 'Policies &amp; Terms of Service',
        width: 600,
        height: 400,
        modal: true
    });

Also, make sure you are attaching $tos_dlg to the DOM somewhere, via something like $tos_dlg.appendTo("#containerElement").

like image 147
gilly3 Avatar answered Dec 30 '22 05:12

gilly3


Try this:

var $tos_dlg = $('<div></div>').html($(this).load('/includes/tos.html'));
$("body").append($tos_dlg);
$tos_dlg.dialog({
    autoOpen: false,
    title: 'Policies &amp; Terms of Service',
    width: 600,
    height: 400,
    modal: true
});
like image 21
brenjt Avatar answered Dec 30 '22 05:12

brenjt