I'm fed up of writing the same code over and over again, so trying to get to grips with doing my own jQuery extension to simplify and replace some of the most common repetitions.
So after reading a few webpages, a few chapters, and asking a few questions on here, Ive come up with the following code:-
(function( $ ) { $.fn.tcDialogue = function(options) { $('body').append("hello"); var closeDialogue = function(other_args) { alert("I would close if I was written"); }; }; }(jQuery)); $(document).ready(function (){ var testDialogue = tcDialogue(); testDialogue.closeDialogue(); });
Which should (as far as I'm aware) put 'hello' into the body, and then display an alert, however all I get from my browser is 'tcDialogue' is not declared, so I'm obviously doing something wrong, but does anyone have any ideas as to what I've done wrong?
(function ($) { $.fn.tcDialogue = function (options) { this.append("hello"); var closeDialogue = function (other_args) { alert("I would close if I was written"); }; return { closeDialogue: closeDialogue }; };}(jQuery));$(document).ready(function () { var testDialogue = $('body').tcDialogue(); testDialogue.closeDialogue();});
http://jsfiddle.net/BvssN/
Open in new window