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

  • Home
  • SEARCH
  • 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 6671263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:22:03+00:00 2026-05-26T03:22:03+00:00

I am trying to understand how to write custom functions in jquery. I have

  • 0

I am trying to understand how to write custom functions in jquery.

I have this code:

<head>
.
.
<script src="js/jquery.js"></script>
<script>
     $(document).ready(function(){
       $("createaccountbtn").click(function(e){            
            e.preventDefault();
            alertMe();
       });
     });

     (function( $ ) {
        $.fn.alertMe = function() {
          alert("hello world!");
        };
     })( jQuery );
</script>
</head>

<body>
<h1>Create Account</h1>
<div id = "wrapper">
<form name = "createaccountform" action = "php/createaccount.php" method = "post">
<p>First Name<input name = "fName" type="text" size="25"/><label id ="fNameStatus"></label></p>

<p>Last Name<input name = "lName" type="text" size="25"/><label id ="lNameStatus"></label></p>

<p>E-mail<input name = "email" type="text" size="25"/><label id ="emailStatus"></label></p>

<p>Confirm E-mail<input name = "email" type="text" size="25"/><label id ="emailStatus"></label></p>

<p>Password<input name = "pass" type="text" size="25"/><label id ="passwordStatus"></label></p>

<p>Confirm Password<input name = "cpass" type="text" size="25"/><id name ="cpasswordStatus"></label></p>

<p><input id = "createaccountbtn" type ="button" value="Create Account"/></p>
</form>
</div>
</body>

I am trying to execute a custom function when the user clicks the “Create Account” button, but I cannot get it to work. Any ideas what’s up?

  • 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-26T03:22:04+00:00Added an answer on May 26, 2026 at 3:22 am

    This code:

    (function( $ ) {
        $.fn.alertMe = function() {
          alert("hello world!");
        };
    })( jQuery );
    

    adds a function called alertMe to the jQuery prototype, which will let you call $("div").alertMe();

    To call it as you are, just declare a regular function:

    function alertMe () {
        alert("hello world!");
    }
    

    Also, $("createaccountbtn") is not a valid selector, as it will try to select anything with a tagName of createaccountbtn – make sure to prepend it with a #.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to understand something with pointers, so I wrote this code: #include
Trying to understand Ruby a bit better, I ran into this code surfing the
I'm trying to understand this: http://tcs.uj.edu.pl/~walczak/fibonacci.pdf I have a word created from a concatenation
I'm trying to understand whay i get an error on this code: (the error
I'm trying to write custom authentication domain service. I think I understood all code
I'm trying to understand the format of the Javascript functions that jQuery, among other
After trying to understand why client code is not rendered in a page (injected
Just trying to understand that - I have never used it before. How is
I am trying to understand the boost array . The code can be read
I am trying to understand what is IAsyncresult good and therefore I wrote this

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.