Reputation: 171
So I have 2 divs, each with n-elements. There are n-pairs of elements across the 2 divs. Each pair uses the same 'class'.
Is it possible to remove a particular pair at a time? I currently am using the following code:
function leaveGroup(id)
{
var e = document.getElementById(id);
var f = $(e).parentNode;
// Remove everything with the same class name of the parent
$('body').removeClass($(f).className);
}
The function isn't working, am I using class names incorrectly? Thanks!
Upvotes: 2
Views: 5341
Reputation: 97
When you said, remove you want to remove the class of element? If you want to remove element, you can make this:
div = document.getElementByClassName('yourClass');
Now you have a collection of itens and now you can remove the item you want, ex:
div[1].remove();
if you want to remove all at once
for(i in div){ i.remove(); }
Upvotes: 0
Reputation: 186562
$('.el').remove()
// would remove all elements with the 'el' className
I believe this is what you want. removeClass
removes a class. remove
removes the element.
Upvotes: 7
Reputation: 887453
You're misunderstanding jQuery.
The removeClass
function removes a class from an existing element.
You want to write the following:
var className = $('#' + id).parent().attr('class');
$('.' + className).remove();
Note that this won't work if the parent node has multiple classes.
Upvotes: 2