Reputation: 11663
<li>ff<strong>foobar</strong><a class="icon-close" href="#."></a></li>
<li>ff<strong>foobar</strong><a class="icon-close" href="#."></a></li>
<li>ff<strong>foobar</strong><a class="icon-close" href="#."></a></li>
<li>ff<strong>foobar</strong><a class="icon-close" href="#."></a></li>
<li>ff<strong>foobar</strong><a class="icon-close" href="#."></a></li>
<li>ff<strong>foobar</strong><a class="icon-close" href="#."></a></li>
<li>ff<strong>foobar</strong><a class="icon-close" href="#."></a></li>
On clicking the a
, the respective li
should be deleted.
$(.close-icon).hide();
hides every thing.
Upvotes: 0
Views: 408
Reputation: 15867
$(".close-icon").click(function() {
$(this).closest("li").remove();
});
This will not only hide the element, it will also remove it from the page.
Upvotes: 3
Reputation: 14318
Do you mean this
$('.close-icon').click( function (){ $(this).hide(); });
For hiding the entire parent
$('.close-icon').click( function (){ $(this).parent('li').hide(); });
Also change .close-icon
to '.close-icon'
for removing
replace hide()
by remove()
Upvotes: 1
Reputation: 54022
try
$("a").click(function() {
$(this).closest("li").hide();
});
$("a").click(function() {
$(this).closest("li").empty();
});
OR
$("a").click(function() {
$(this).closest("li").remove();
});
Upvotes: 2
Reputation: 20364
$("a.close-icon").click(function() {
$(this).parent("li").remove();
return false;
});
Upvotes: 0
Reputation: 2236
I have not tested, but code below should work, if I understood your requirement.
$(.close-icon).click(function(event){
event.preventDefault();
$(this).parent().remove(); //remove the parent OR
//$(this).parent().hide(); //hide the parent
});
Upvotes: 0
Reputation: 50019
if you want to hide it
$('a.icon-close').click(function(){
$(this).parent('li').hide();
});
If you want to delete it
$('a.icon-close').click(function(){
$(this).parent('li').remove();
});
The filtering 'li' in .parent()
is not strictly necessary in this case.
Upvotes: 0
Reputation: 40535
Presuming you want the li to hide / remove on click of the icon
$('.close-icon').click(function(){
$(this).parent('li').hide();
});
or
$('.close-icon').click(function(){
$(this).parent('li').remove();
});
Upvotes: 0
Reputation: 21892
Should work, but haven't tested:
$("a.close-icon").click(function() {
$(this).parent("li").hide();
});
Upvotes: 6