Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery dialog window example not working

Tags:

jquery

Trying to learn Jquery and am on the verge of giving up!! Have spent 2 days trying to get a dialog box to display!

Can anyone help as to why this code doesnt work? I just get hello at the top of the page!

jQuery:

<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/jquery.ui.core.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
    var $dialog = $('#dialog')
    //.html('This dialog will show every time!')
    .dialog({
        autoOpen: false,
        title: 'Basic Dialog'
    });
    $('#opener').click(function() {
        $dialog.dialog('open');
        // prevent the default action, e.g., following a link
        return false;
    });
});
</script>

HTML

<div id="dialog">hello</div>
<button id="opener" style="margin-left:66px;margin-top:3px;font-size:11px;width:60px">Click</button>
like image 561
JC75 Avatar asked Sep 07 '26 08:09

JC75


1 Answers

Make sure your jQuery UI Core file has included the Widget factory. Take a look:

http://jqueryui.com/download

Even if you don't have the jQuery UI CSS file included, it should still work:

See jsFiddle demo


Try this exact code that I have out at jsBin:

<!DOCTYPE html>
<html>
<head>
  <meta charset=utf-8 />
  <title>jQuery Dialog Demo</title>
  <link rel="stylesheet" type="text/css" href="//ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/cupertino/jquery-ui.css" />
</head>
<body>
  <div id="dialog" style="display: none;">hello</div>
  <button id="opener">Open Dialog</button>
  <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.2.min.js"></script>
  <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.min.js"></script>
  <script type="text/javascript">
    var $dialog = $("#dialog").dialog({ autoOpen: false, title: "Basic Dialog" });
    $("#opener").click(function() { $dialog.dialog("open"); });
  </script>
</body>
</html>
like image 54
Code Maverick Avatar answered Sep 09 '26 23:09

Code Maverick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!