Jquery building function

Posted on 2013-11-12
Medium Priority
Last Modified: 2013-12-05
I've been looking at creating my own function, and although I've managed to pass parameters into my function with success, however I'm confused as to how to add functions to my function and how to make the function call with my code.

I've been looking at tutorials but cant seem to any tutorials about how to add functions, and how to call them in my code creation.

Does anyone have any tutorials that can help? Or any suggestions, or code examples?

Thank you
Question by:tonelm54
  • 2
LVL 17

Expert Comment

ID: 39642540
<competing site link removed - GaryC123>

(function($) { 
    $.fn.foo = function(options) {
        // whatever $().foo() should do

        var do_stuff = function(do_stuff_args) {
            console.log("hello world!");
            // do stuff with options and do_stuff_args

            var do_other_stuff = function(other_args) {
                alert("who are you?");
                // here you have access to options, do_stuff_args, and other_args

            return {
                do_other_stuff: do_other_stuff

        return {
            do_stuff: do_stuff

Open in new window

And call it using:


var a = foo(stuff).do_stuff(some_options);

Open in new window


Author Comment

ID: 39643982
Ok, so from what I understand and from what you have said, I have written:-
	(function( $ ) {
		$.fn.tcDialogue = function(options) {
            var closeDialogue = function(other_args) {
                alert("I would close if I was written");
	}( jQuery ));

	$(document).ready(function (){
		var testDialogue = $.tcDialogue();

Open in new window

However I keep getting an error saying that tcDialogue();
LVL 17

Accepted Solution

OmniUnlimited earned 2000 total points
ID: 39648047
No, you have your var declared wrong.  It should read:

var testDialogue = $tcDialogue();

Open in new window


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question