JQuery dialog.html () question

I use the jquery dialog and want to set the .html value with an external html file located on the same server. What I'm not sure 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 .html () is called is where I want to enter the contents of an external file. I think the .load function will work somehow, but I'm just not sure if this is the right approach, and if so, how to implement it exactly. Can anyone help?

thanks

+4
source share
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 attach $tos_dlg to the DOM somewhere using something like $tos_dlg.appendTo("#containerElement") .

+9
source

Try the following:

 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 }); 
+1
source

All Articles