Ah, so extensions are the way to go. Cool, I'll take a look at those. @Kean: Actually, I'm trying to keep my $(document).ready(function() {}); as clean as possible. I prefer to use it instead of my old init () function and call as much functionality as possible via outside functions instead of putting it all between those brackets. Seems like I'll have to re-write those outside functions as jQuery extensions, which is good to know but which also surprises me a lot (I'd expect a "make things easier"-framework to be able to better handle something so basic as calling another non-jQuery function with arguments).
Thanks all! On Dec 16, 12:23 am, "Rik Lomas" <lomas....@gmail.com> wrote: > The simplest way would be to do something like test($(this)); as test > is a function, not a method of the jQuery object. > > The more complex way would be to extend jQuery to allow method so you > could use $(this).test();http://docs.jquery.com/Core/jQuery.fn.extend > > Rik > > 2008/12/15 WebGrunt <bievie...@gmail.com>: > > > > > > > Hi > > > I'm new to jQuery and here's one thing that doesn't make sense. How > > do I link an existing function with "this" as argument to a div? > > > The function to be called is really simple: > > > function test(e) > > { > > alert(e.id); > > //Also tried e.getAttribute("id") or e.attr("id") > > } > > > Here is what I tried so far inside the $(document).ready(function() > > {}); part: > > > $("div.someClass").each(function(){ > > $(this).test(); > > }); > > > $("div.someClass").each(function(){ > > $(this).test; > > }); > > > $("div.someClass").each(function(){ > > $(this).click(test); > > }); > > > $("div.someClass").each(function(){ > > $(this).click(test()); > > }); > > > Alternatively, I tried: > > > function test(strId) > > { > > alert(strId); > > } > > > $("div.someClass").each(function(){ > > var strId = $(this).attr("id"); > > $(this).test(strId); > > }); > > > $("div.someClass").each(function(){ > > var strId = $(this).attr("id"); > > $(this).click(test(strId)); > > }); > > > Can someone point me in the right direction? Maybe it's just one of > > the many different combo's I haven't tried, but I'm rather amazed that > > something this basic is so difficult to get right (and find > > documentation on). > > > Thanks! > > -- > Rik Lomashttp://rikrikrik.com