KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Does anyone know how to create a jQuery Dialog in a function? I can't find an attribute to set the message... In every example I found, the dialog has been statically written into the code in a div-tag. However, I want to create it dinamically, so I need to know how to create a dialog in a function. It is no problem to set the title: <script> // increase the default animation speed to exaggerate the effect $.fx.speeds._default = 1000; $(function() { $( "#dialog" ).dialog({ autoOpen: false, show: "blind", hide: "explode" }); $( "#opener" ).click(function() { //$( "#dialog" ).dialog( "open" ); $( this ).dialog({ title: 'Please confirm deletion!' }); return false; }); }); </script> </head> <body> I have the documentation and some examples here . Thanks for helping out guys. Cheers, doonot ============================= [SOLUTION]===================================== Thanks for all who answered this questions. This is how i wanted it: function createDialog(title, text) { return $("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>") .dialog({ resizable: false, height:140, modal: true, buttons: { "Confirm": function() { $( this ).dialog( "close" ); }, Cancel: function() { $( this ).dialog( "close" ); } } }); } And it can be called for example like this (clicking on an image): <img src="delete.png" onClick="createDialog('Confirm deletion!', 'Do you really want to delete this package?')">
Tags (comma-separated)
Save Edits
Cancel