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 736045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:33:35+00:00 2026-05-14T07:33:35+00:00

I am relatively new to implementing JQuery throughout an entire system, and I am

  • 0

I am relatively new to implementing JQuery throughout an entire system, and I am enjoying the opportunity.

I have come across one issue I would love to find the correct resolve for.

Here is a simple case example of what I want to do:

I have a button on a page, and on the click event I want to call a jquery function I have defined.

Here is the code I have used to define my method (Page.js):

(function($) {
 $.fn.MessageBox = function(msg) {
  alert(msg);
 };
});

And here is my HTML page:

<HTML>
<head>
 <script type="text/javascript" src="C:\Sandpit\jQueryTest\jquery-1.3.2.js"></script>
 <script language="javascript" src="Page.js"></script>
</head>
<body>
 <div class="Title">Welcome!</div>
 <input type="button" value="ahaha"  onclick="$().MessageBox('msg');" />
</body>
</HTML>

(The above code displays the button, but clicking does nothing.)

I am aware I could add the click event in the document ready event, however it seems more maintainable to put events in the HTML element instead. However I have not found a way to do this.

Is there a way to call a jquery function on a button element (or any input element)? Or is there a better way to do this?

Thanks

EDIT:

Thank you for your responses, it appears I am not using JQuery correctly. I would really love to see an example of a system using JQuery this way and how events are handled. If you know of any examples to demonstrate this please let me know.

My underlying goal for using JQuery is to help simplify and reduce the amount of javascript required for a large-scale web application.

  • 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-05-14T07:33:35+00:00Added an answer on May 14, 2026 at 7:33 am

    I don’t think there’s any reason to add this function to JQuery’s namespace. Why not just define the method by itself:

    function showMessage(msg) {
       alert(msg);
    };
    
    <input type="button" value="ahaha" onclick="showMessage('msg');" />
    

    UPDATE: With a small change to how your method is defined I can get it to work:

    <html>
    <head>
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
     <script language="javascript">
        // define the function within the global scope
        $.fn.MessageBox = function(msg) {
            alert(msg);
        };
    
        // or, if you want to encapsulate variables within the plugin
        (function($) {
            $.fn.MessageBoxScoped = function(msg) {
                alert(msg);
            };
        })(jQuery); //<-- make sure you pass jQuery into the $ parameter
     </script>
    </head>
    <body>
     <div class="Title">Welcome!</div>
     <input type="button" value="ahaha" id="test" onClick="$(this).MessageBox('msg');" />
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Relatively new to mySQL so this is probably an easy one: I have a
I am relatively new to JMS and have encountered a weird problem implementing my
I'm implementing a new iPhone app and am relatively new to Cocoa development overall.
Relatively new to JQuery. I've got some code that does a banner swap with
I am relatively new to ASP.NET programming, and web programming in general. We have
I'm implementing a relatively simple autosave system and I'd like to do so using
I am relatively new to web development and learning all the time. I have
I'm relatively new in the Java world and I have a problem which I
I have come unstuck on a relatively (almost) trivial problem. I have a row
Relatively new with SVN. I am using svn on local system (OpenSuSE 11.3). I

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.