views:

76

answers:

1

I have this working script (i know its incomplete):

function rsvpNew(selector,function_url) {
 $(selector).livequery('click',function(){
   var select = $(selector).attr('rel');
   var event_id = $(this).parents('ul.event-options').attr('rel');
   element = this;

   switch(select) {
        case "attending":
     $.ajax({
     type: "POST",
     url: "/events/set_member/"+function_url,
     data: "event_id="+event_id,
     beforeSend:  function() {
     $("<span class='notice'>Saving...</span>").prependTo('body');
               },
     complete: function() {


       $('span.notice').fadeOut(500);
       $(element).closest('span.rsvp-status').html("I'm Attending &ndash; <a href='javascript:;' class='remove' rel='remove'>Remove</a>");
       }


     });


          break;

Now the line

$(element).closest('span.rsvp-status').html("I'm Attending &ndash; <a href='javascript:;' class='remove' rel='remove'>Remove</a>");

Is working, but when I do something similar to get the parent ul of this li, it doesn't work. Any ideas?

A: 

but when I do something similar to get the parent ul of this li, it doesn't work. Any ideas?

To get the parent of something you can use a few options:

$('li').parent('ul'); //will return your ul

Gets the direct parent of an element.

Another way is to use closest:

$('li').closest('ul'); //should also return your ul

Gets a set of elements containing the closest parent element that matches the specified selector. Especially useful for event delegation.

Colin
True but when I moved it outside of the complete function, and change element back to this, it works fine. element variable is "this" and works for the line above it.
matthewb