Topic: $(this) selector in js.erb files ?


I made a grid where crete/update/delete actions work with ajax (tutorial). Every row in the grid has an Edit link, which triggers the following in edit.js.erb:

$("#my_form").html("<%= escape_javascript( render 'widgets/form' ) %>");
#This snippet inserts "form" partial into "my_form" div which is located down on the page.

But how can I insert it on the same line where the Edit link resides?

The following didn't work:

$(this).closest('td').html("<%= escape_javascript( render 'widgets/form' ) %>");

... assuming that $(this) represents the clicked Edit link.

Please, help me.

* Update *

I found a great tutorial: Rails 3 Remote Links and Forms: A Definitive Guide. It explains everything.

Last edited by neomatrix (2010-11-16 05:09:45)