views:

78

answers:

3

here is the deal.

i have several templates for faceboxes (lightbox) i need at different points of the application. these are stored in different partials and files.

i will initialize different javascript functions in accordance to which ones i need. The question is, what is the best way to append the external HTML page into my body using javascript?

A: 

Since you tagged the question with it, here's a jQuery solution.

$("body").append("text");

Remember that the parameter can also be a DOM element. So you can do this :

var p = $("<p/>").text("a paragraph");
$("body").append(p);
çağdaş
A: 

I think he is asking for how he can append a rails PARTIAL into it without necessarily mixing rails and js code

meow meow meow
+1  A: 

the easy way with jQuery is:

$('#result').load('test.html');

<div id="result"><!--/ Hold My Data! /--></div>

obviously you can change #result with body

aSeptik
thanks! this was super helpful. any idea how this can be done in in rails? it is often a partial (_partial.html.erb), which cannot be called as ("/partial")
ming yeow
If you want to load those partials dynamically with js, you'll have to expose each of them with a route. Replace `test.html` with `/path/to/my/action/to/render_partial`. Alternately, if you know you'll need them, render the partials into the view and hide them with `display:none;` until you use them in your facebox.
Jonathan Julian
Read This http://stackoverflow.com/questions/2229811/load-partial-with-jquery-and-rails AND this http://stackoverflow.com/questions/2484958/rails-ajax-jquery-problem
aSeptik