views:

77

answers:

2

I tried this to remove the adjacent li, but it doesn't work:

   $(this).prev(".Removable").remove();

Edit: I only want to remove the immediate adjacent li if it has that class.

 WHEN SELECTABLE IS CLICKED I WANT THE PREVIOUS REMOVABLE TO VANISH

  <ul>

  <li class="Removable">   <li>
  <li class="Selectable">   <li>
  <li class="Removable">     <li>

  <ul>
+1  A: 

Without seeing your html structure it's hard to tell the best selector to use, but you can try a catch-all traversal with closest, to hit the current <li> no matter where you start traversing from:

$(this).closest('li').prev('li.Removable').remove()

See Traversing/closest.

Roatin Marth
downvoted because this doesn't match what he needs, now that he's posted the HTML
fudgey
@fudgey: actually this answer still works with the posted HTML. Maybe you misunderstood the question?
Roatin Marth
+2  A: 

It worked for me: http://jsbin.com/esija/edit

$(document).ready(function() {
  $(".Selectable").click(function(){
    $(this).prev(".Removable").remove();
    return false;
  })
});

But it only removes the previous sibling as advertised.

jjclarkson
It appears that zsharp only wants the removing to happen when "Selectable" is clicked. Your code triggers when "Removeable" is clicked.
jessegavin
There, fixed that...
jjclarkson