looking for a very simple implementation of modal dialog box without using jquery UI.
just for example
Here's a very basic version:
$("<iframe id='shim' src='http://jsbin.com/abira4'>").css({
width: "100%",
height: "100%",
position: "absolute",
left: "0px",
top: "0px",
zIndex: "100",
backgroundColor: "#fff",
opacity: "0.5"
}).appendTo(document.body);
$("<div>Hi there, click me to dismiss</div>").css({
zIndex: "101",
border: "1px solid black",
backgroundColor: "#ecc",
position: "absolute",
left: "100px",
top: "100px"
}).appendTo(document.body)
.click(function() {
$(this).remove();
$("#shim").remove();
});
Live example
How it works:
#f0f0f0
and opacity is 50%) so it "greys out" the underlying document. This is absolutely positioned at 0,0 with 100% width and height, and a z-index of 100 (this has to be higher than anything else on the page). The src
of the iframe should be a blank document.Now, there are a lot of variations. For instance, there's no reason at all you can't have the model div markup in the HTML document rather than in the script — -- just give it display: none
until you need it. Things like that.
Obviously, this version lets you click anywhere on the dialog box to dismiss it, but it's easily modified to only allow closing with an [X] somewhere. And to say that it could use some styling would be to...put it mildly.
All that said, I can't claim it's remotely bulletproof. That's why well-tested plug-ins are for. :-)
I think you're looking for something like this:
$('.modal .titlebar a').click(function() {
$(this).parents('.modal').hide();
});
$('button.open-modal').click(function() {
$('#something').show();
});