Right, my mistake. Only in the <body> onclick handler 'this' refers to window. It's been such a long time since I last used inline handlers that I'd forgotten :)
On Jan 24, 9:55 pm, candlerb <b.cand...@pobox.com> wrote: > I found the solution. Whilst jRails uses jquery-ui-1.5, it is still > using jquery-1.2.6, and "closest" is a 1.3 feature. > > The following works just fine: > > <a href="#" onclick="$(this).parents('.setting').remove()">remove</ > a> > > Ricardo Tomasi wrote: > > 'this' in an attribute event handler refers to 'window', not the > > element itself. > > In my copy of JavaScript, The Definitive Guide (5th ed), it says > (p396) > > "Whether you define an event handler with an HTML attribute or with a > JavaScript property, you are assigning a function to a property of a > document element. In other words, you're defining a new method of the > document element. When your event handler is invoked, it is invoked as > a method of the element on which the event occurred, so the 'this' > keyword refers to that target element. This behavior is useful and > unsurprising" > > Regards, > > Brian.