Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery dialog on button click

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!

like image 799
user763460 Avatar asked Nov 27 '12 20:11

user763460


2 Answers

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

like image 50
Sushanth -- Avatar answered Sep 18 '22 00:09

Sushanth --


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>
like image 34
cssyphus Avatar answered Sep 20 '22 00:09

cssyphus