My goal is to have a different dialog box appear for each item clicked. I currently have one setup and figured I can just add an if statement. If mousedown on div_a, dialog_a, else if mousedown on div_b, dialog_b, etc... I am new to coding and cant figure this one out.
Here is my code for the dialog:
$(document).ready(function(){
$("#questiona").mousedown(function(){
$("#dialoga").dialog();
});
});
Since you are new to coding, I suggest using the jQuery team's jQueryUI library -- which includes a
.dialog()
capability (they call it a "widget"). Here's how it works:(1) Include both jQuery and the jQueryUI libraries in your
<head></head>
tags. Note that you must also include an appropriate CSS theme library for jQueryUI (or the dialogs will be invisible):(2) Create an empty div in your HTML, and initialize it as a dialog:
HTML:
jquery:
(3) Then, when you are ready to display the dialog, insert new data into the
myDlg
div just before opening the dialog:The above allows you to change the content of the dialog and use the re-same dialog DIV each time.
Here's what the working example would look like:
jsFiddle Demo
HTML:
jQuery:
Resources:
How to use Plugins for PopUp
http://jqueryui.com/dialog/
http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/
jQuery UI Dialog Box - does not open after being closed
Dynamically changing jQueryUI dialog buttons
jQuery UI dialog - problem with event on close