Reputation: 7164
I have a JavaScript method which calls a jQuery function inside :
function diyalog()
{
$(function() {
$( "#dialog" ).dialog();
});
}
And I get this error :
TypeError: $(...).dialog is not a function
How can I call this jQuery method from my JavaScript method properly. Thanks.
Upvotes: 0
Views: 76
Reputation: 1095
A couple of things: remove the $() wrapper around your jQuery call, as this is a closure (Immediately Invoked Function Expression) that it used to invoke javascript on document load.
Also include jQuery.UI on your page, as the dialog plugin exists in this library.
Upvotes: 1
Reputation: 6253
Be sure to include jQuery and jQuery UI:
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
<script>
$(function() {
$( "#dialog" ).dialog();
});
</script>
Upvotes: 1
Reputation: 23816
Your code is seems fine:
function diyalog(){
$("#dialog-message").dialog();
}
diyalog();//calling
You are missing jquery Ui. https://code.jquery.com/ui/. Add this in your html file:
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
Upvotes: 1