On Oct 30, 4:42 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hey > > I've written small functions for DOM traversal and placed them in > jquery.plugins.js: > > jQuery.fn.prevUntil = function(expr) { > var match = []; > this.each(function(){ > var n = this; > while (n = n.previousSibling) { > if (n.nodeType == 1) match.unshift(n); > }; > }); > return this.pushStack(jQuery.multiFilter(expr, match)); > > } > > jQuery.fn.nextUntil = function(expr) { > var match = []; > this.each(function(){ > var n = this; > while (n = n.nextSibling) { > if (n.nodeType == 1) match.push(n); > }; > }); > return this.pushStack(jQuery.multiFilter(expr, match)); > > } > > I linked jQuery and this script in HTML and another file with main > scripts: > > <script type="text/javascript" src="js/jquery.js"></script> > <script type="text/javascript" src="js/jquery.plugins.js"></script> > <script type="text/javascript" src="js/main.js"></script> > > Everything worked well. Then I found great dimensions > pluginhttp://brandonaaron.net/docs/dimensions/and tried to paste in to > jquery.plugins.js. I tried minified and normal version, but after > pasting, I get an error in my original code. > > jQuery.fn.prevUntil = function(expr) { > var match = []; > this.each(function(){ // HERE > ... > > It says that this.each is no a function (jquery.plugins.js, line 16th) > > Plugin is wrapped in anonymous function (function($){...})(jQuery); > > How can I connect these two pieces of code in one file without > breaking anything? Rest assured, that main.js doesn't interfere with > jQuery nor Plugins, I even deleted it to check. > > Thanks in advance
I'm pretty sure the issue is that you are calling a jQuery function before it has been loaded. You need to put your functions inside of a "document ready" function: $(document).ready(function () { jQuery.fn.prevUntil = ... jQuery.fn.nextUntil = ... }); -Eric