$("#dialog") Is not a function error

$("#dialog") Is not a function error

I want to pass a data(text) to the dialog.
Inside
  1. $(document).ready(function()

I have

  1. function openDialog() {
                    $("#dialog").dialog({
                        autoOpen: false,
                        resizable: false,
                        height: 180,
                        width: 350,
                        modal: true,
                        open: function(event, ui) {
                            var dialog = $("#dialog");
                            dialog.data = dialogText;
                        }
                    });
                }

Then somewhere I call it

  1. afterSubmit: function(response, postdata) {
                            if (response.responseText != "") {
                                var userKey = JSON.parse(response.responseText).UserKey;
                                jQuery(gridSelector).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
                                dialogText = userKey;
                                openDialog();
                                return [true, "OK"];
                            } else {
                                return [false, "error"];
                            }
                        },

However I get the $("#dialog") is not a function error.