javascript - Custom jQuery Functions -


i trying understand how write custom functions in jquery.

i have 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 trying execute custom function when user clicks "create account" button, cannot work. ideas what's up?

this code:

(function( $ ) {     $.fn.alertme = function() {       alert("hello world!");     }; })( jquery ); 

adds function called alertme jquery prototype, let call $("div").alertme();

to call are, declare regular function:

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

also, $("createaccountbtn") not valid selector, try select tagname of createaccountbtn - make sure prepend #.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -