4

I'm trying to get a jquery dialog to launch on a button click but does not seem to be working. Any help would be appreciated:

 $('#wrapper').dialog({
 autoOpen: false,
 title: 'Basic Dialog'
 });
 $('#opener').click(function() {
 $(this).dialog('open');
 return false;
 });
 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<button id="opener">Open the dialog</button>
 <div id="wrapper">
 <p>Some txt goes here</p>
 </div>

Thanks!

Pratyush
5351 gold badge8 silver badges18 bronze badges
asked Nov 27, 2012 at 20:23

3 Answers 3

7

This line

$(this).dialog('open'); // this here corresponds to the #opener div

supposed to be

$('#wrapper').dialog('open');

Also extra braces }); .. Can be ignored if this is the closing brace for DOM Ready handler

Check Fiddle

answered Nov 27, 2012 at 20:27
0
3

Ensure you are referencing the jQuery and jQueryUI libraries, as per my example below.

Try this:

<html>
 <head>
 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
 <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
 <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" media="all" />
 <script type="text/javascript">
 $(document).ready(function() {
 $('#wrapper').dialog({
 autoOpen: false,
 title: 'Basic Dialog'
 });
 $('#opener').click(function() {
 $('#wrapper').dialog('open');
// return false;
 });
 });
 </script>
 </head>
<body>
<button id="opener">Open the dialog</button>
<div id="wrapper">
 <p>Some txt goes here</p>
</div>
answered Nov 27, 2012 at 20:31
1

Try this code, it works for me.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
<script>
$(document).ready(function() {
 $(function() {
 console.log('false');
 $( "#dialog" ).dialog({
 autoOpen: false,
 title: 'Test'
 });
 });
 $("button").click(function(){
 console.log("click");
 $(this).hide();
 $( "#dialog" ).dialog('open');
 });
}); 
</script>
</head>
<body>
<button id="open">Open Dialog box</button> 
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
</body>
</html>
Jabbar
6101 gold badge9 silver badges21 bronze badges
answered Apr 2, 2016 at 10:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.