tags:

views:

154

answers:

2

Given

$(".foo").editable("script.php")

How can I pass the ID of .foo's parent as a parameter? I've tried

$(".foo").editable("script.php", { 

     submitdata: {

          parent_id: $(this).parent().attr('id')

                 }
     });

and every variant of that I can think of, but it just seems like the $(this) object is not working in this context.

A: 

I would just do this:

$(".foo").editable("script.php", { submitdata: { parent_id: $(".foo").parent().attr('id') } });

You also have a typo in your question, you have $(.foo).editable() instead of $(".foo").editable(). If that is also in your actual code, that may be the source of the problem.

Julian
That was just a typo in the question.Thanks for the response, that does get the ID of the parent, and would be fine if it was $("#foo") instead of $(".foo").. but in this case, it's a class, and there's multiple $(".foo")s... so i need it to reference itself, and not the whole class.
Matthew
+1  A: 

had the same problem here, found the following solution:

$('.jeditable').each(function() {
   var $this = $(this);
   $this.editable('submit.jsp', {
      submitdata  : { parent_id : $this.parent().attr('id') }
   });
});