Reputation: 1043
I have html scheme like
<li>Some text <a href='#' class='click'>Remove</a> <input type='hidden' ></li>
And i have OnClick function like
$(".click").click(function() {
// i need to select 'li' and then delete it
// i have this code, but its not working
$(this).prev('li').remove();
return false;
});
How do I Select previous html tag onClick ?
Upvotes: 0
Views: 186
Reputation: 160833
.prev
is for siblings, in your case, li
is parent, so you could use .closest
.
$(".click").click(function () {
$(this).closest('li').remove();
return false;
});
Upvotes: 3
Reputation: 58962
li
is not the previous element, but the parent:
$(".click").click(function () {
$(this).parent().remove();
return false;
});
Upvotes: 6