0

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.

asked Sep 10, 2014 at 11:57
1
  • 6
    Have you already added jQuery UI to your file? Commented Sep 10, 2014 at 11:59

3 Answers 3

1

Your code is seems fine:

function diyalog(){
 $("#dialog-message").dialog();
}
diyalog();//calling

Working DEMO

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>
answered Sep 10, 2014 at 12:03
Sign up to request clarification or add additional context in comments.

Comments

1

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>
answered Sep 10, 2014 at 12:05

Comments

1

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.

answered Sep 10, 2014 at 12:13

Comments

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.