I put together an overly simplistic jsFiddle demo of how a popup is made. Here is the magic:
//Display Popup method - you can modify this to add parameters
function displayPopup(event) {
//dynamically create a div, button, and inner text
var p = document.createElement('div'),
b = document.createElement('button'),
t = document.createTextNode("Text and stuff");
//add popup class to newly created div
p.className += 'popup';
//Add text to close button element
b.innerHTML = "close";
//Append text to popup div
p.appendChild(t);
//Bind click event to button element
b.onclick = closePopup;
//Append button to popup div, and append popup to document body
p.appendChild(b);
document.body.appendChild(p);
p.style.display="block";
//This function hides the popup
function closePopup(event){
p.style.display="none";
}
}
It should by no means be considered complete or production material, but I hope it helps you get started on the right path to extending it to achieve the functionality you're looking for.