I am trying to convert the following Prototype code to jQuery:

<div class=".thing">
  ...
  <a href="#" onclick="$(this).up('.setting').remove()">remove</a>
</div>

Basically, when a user clicks on the 'remove' link I want the entire
enclosing div which contains this link to vanish from the DOM. But
there are multiple divs, each with their own 'remove' links. (*)

With jQuery I have tried onclick="$(this).closest('.setting').remove
()" but it doesn't work - nothing happens. To debug I tried
onclick="alert($(this).toSource())" and it showed me an empty object.

I am sure I'm missing something obvious. When I google for this I just
get examples where a click callback function is registered - $(this)
is set appropriately within the callback. But here I just want to
stick some Javascript inline in an onclick="..." handler.

Many thanks,

Brian.

(*) Aside: original Prototype-based code taken from 
http://railscasts.com/episodes/75
- I am migrating this app to jQuery using jRails.

Reply via email to