I'm new to jquery. I attempted to make a jquery dialog box on a dynamic html content. I tried in two different ways. be that as it may, its not working? What is the amiss with the code. pls help me.
1 try $('#opener').on('click', function(){ //action });
2 try $(document).on('click', '#opener', function(){ //action });
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Dialog - Animation</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
</head>
<body>
<button id="opener">Open Dialog</button>
<div id="new_dialog_area"></div>
</body>
</html>
<script>
$(function() {
function makedialog(){
var htmlData = '<div id="dialog" title="Basic dialog">';
htmlData += '<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>';
htmlData += '</div>';
$('#new_dialog_area').html(htmlData);
}
// $('#opener').on('click', function(){
$(document).on('click', '#opener', function(){
makedialog();
$("#dialog").dialog({
autoOpen:false,
});
$("#dialog").dialog("open");
});
});
</script>