[jQuery] Re: How to link myFunction(this) to a div

2008-12-16 Thread WebGrunt
Thanks, this seems to do the trick. Test() was only as an example, I use different names in my scripts. Seems like I'll have to read up on the different scpes of "this". Thanks all, and sorry for the noob question. :) On 16 déc, 09:22, brian wrote: > On Mon, Dec 15, 2008 at 5:07 PM, WebGrunt

[jQuery] Re: How to link myFunction(this) to a div

2008-12-16 Thread brian
sorry about the wrap. $(document).ready(function() { $("div.someClass").click(function() { /* note: no $() so you pass the element, * not the jQuery object */ elementTest(this); }); });

[jQuery] Re: How to link myFunction(this) to a div

2008-12-16 Thread brian
On Mon, Dec 15, 2008 at 5:07 PM, WebGrunt wrote: > > 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 tr

[jQuery] Re: How to link myFunction(this) to a div

2008-12-15 Thread WebGrunt
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

[jQuery] Re: How to link myFunction(this) to a div

2008-12-15 Thread Kean
I didn't quite get what you meant but by judging on Rik's solution you can integrate custom functions into jQuery (function($) { $.fn.test = function() { alert(this.id); } })(jQuery); // this alerts wellwellwell $("body").test(); On Dec 15, 3:23 pm, "Rik Lomas" wrote: > The simplest

[jQuery] Re: How to link myFunction(this) to a div

2008-12-15 Thread Rik Lomas
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 : > > Hi >