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.

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>
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>

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.

Comments

Your Answer

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.