Dynamic modal dialogs creation from dynamic DOM elements

Dynamic modal dialogs creation from dynamic DOM elements


I'm trying to write a class that would allow me to do this:
var dialog = new v2dialog("Title", "Dialog message.");
test.show();
This code creates a new dom element (<div>) and creates a new jQuery
dialog from it (ideally).
After the dialog is closed, the dom element is destroyed.
These are parts of the js class that I've written to no avail:
this.createDOMElement = function() { //should create a dom <div>
element with required id
this.domElement = document.createElement("div");
this.domElement.setAttribute("id", this.elementID);
this.domElement.setAttribute("title", this.title);
this.domElement.innerHTML = this.message;
}
this.show = function(){ //should create the dialog from the given
element's ID
var dE = this.elementID; //id of the dom element which we
want to become a dialog
var dO = this.dialog_options;//options array for dialog
constructor
$(function(){
dE = "#"+dE;
$(dE).dialog(dO);
});
}
I'd appreciate any help...