views:

75

answers:

4

Let's say i have this code

<p id="test">
  some content
<p>
<a href="#" id="test-link">Open</a>

Now i want -using javascript/jquery- to create a popup window, the window content is the content of test paragraph, when test-link is clicked. How could this be done?

+2  A: 

You can do this using jQuery UI (dialog) (see examples in the reference documentation).

Bruno
Unfortunately, I want a popup window, not a modal or dialog.
Ibrahim Hussein
In this case, the answer by pranay_stacker should work.I tend to prefer dialogs, since they you can get more control regarding their position and they tend to look better. Some people force popups to open in new tabs and/or prevent them from resizing, since these can be annoying depending on the site, especially auto-opening (onload) popups, although few modern websites seem to use those nowadays.
Bruno
+3  A: 
  <a href="javascript:popup();"  id="test-link">Open</a>

function popup()
{
  var generator=window.open('','name','height=400,width=500');

  generator.document.write('<html><head><title>Popup</title>');
  generator.document.write($("#test").html());
  generator.document.write('</body></html>');
  generator.document.close();
}
Pranay Rana
+1  A: 

Use jQuery UI dialog to show popup.

For your html:

$(function()
{
    $("#test-link").click(function()
    {
         $("#test").dialog({ resizable: true,
                modal: false, draggable: true
         });
    });
});

If you don't want to go for jQuery UI dialog then you can use ThickBox.

Krunal
A: 

im using http://defunkt.github.com/facebox/ its nice.

vertazzar