Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:00:17+00:00 2026-06-11T20:00:17+00:00

I cant figure out why I am getting the error: Error: TypeError: $.showMessage is

  • 0

I cant figure out why I am getting the error:

Error: TypeError: $.showMessage is not a function

File 1:

(function($) {
    $.fn.showMessage = function(message, type, delay) {
        var $messages = $("#messages");
        type = (typeof type == 'undefined') ? 'info' : type;
        delay = (typeof delay == 'undefined') ? 0 : delay;

        var message_html = '<div class="messages"><ul>' +
                                '<li class="'+ type +'">' +
                                '<p>' + message + '</p><a href="#" class="close"></a>' +
                            '</li></ul></div>';         

        if($messages.length){
            $messages.html(message_html).hide().delay(delay).fadeIn("fast");
        } else {
            $("#main h1").before(message_html).hide().delay(delay).fadeIn("fast");
        }
        return this;
    };
})(jQuery);

File 2:

(function($) {
    $.showMessage('test','success');
})(jQuery);

Note: it works fine if I have a each() and use a selector $("#messages").showMessage('test','success');. I read somewhere that you always need to return this although can’t figure how to do this without the each()

The below version works fine, although do I really need the each and to pass a selector?

$.fn.showMessage = function(message, type, delay) {
   return this.each(function() {
      var $this = $(this);
        type = (typeof type == 'undefined') ? 'info' : type;
        delay = (typeof delay == 'undefined') ? 0 : delay;

        var message_html = '<div class="messages"><ul>' +
                                '<li class="'+ type +'">' +
                                '<p>' + message + '</p><a href="#" class="close"></a>' +
                            '</li></ul></div>';         

        if($this.length){
            $this.html(message_html).hide().delay(delay).fadeIn("fast");
        } else {
            $("#main h1").before(message_html).hide().delay(delay).fadeIn("fast");
        }
   });
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:00:18+00:00Added an answer on June 11, 2026 at 8:00 pm

    When you use the construct $.fn.showMessage, you are declaring a jQuery plugin named showMessage that will act on a given context, e.g., $("#main").showMessage. To declare a plugin that can be called in a static way, that is, a helper method, you need to declare it outside of the $.fn namespace:

    (function($) {
        $.showMessage = function(message, type, delay) {
          // ...
        }
    })(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am getting Run-time error 13 . Type Mismatch. But i cant figure out why.
Hi I keep getting a syntax error but I cant figure out why. My
Not sure why I'm getting this error and can't figure it out? The cycle
I'm getting the following error message and I can't seem to figure out the
I cant seem to figure out why the style property is not getting updated.
I am getting this error on the following code, and cant figure out why.
I just cant figure out why am getting error 1064 from this query //prep
I'm new to shell scripting but getting this error and cant figure out what
I am getting this error, and cant figure out what the issue is. Server
I can't figure out why I'm getting this error. I only have one class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.