Reputation: 3
I have two elements with the same class - I would like to remove one, but keep another.
For example, I would like to keep this tag:
<div class="chat-column-head chat-container"></div>
But remove this one:
<div class="chat-column-head"></div>
I'd prefer to use this sort of method since I know little about jQuery.
document.querySelector(".id")
Upvotes: 0
Views: 44
Reputation: 548
What you call an "id" is actually called a class name. You can try this :
document.querySelector(".chat-column-head:not(.chat-container)")
It'll select the first .chat-column-head
s element that doesn't have the .chat-container
class.
Upvotes: 3
Reputation: 2596
Here is what you are looking for:
var elementList = document.querySelectorAll(".chat-column-head:not(.chat-container)");
// then iterate over returned list and remove all elements
Array.prototype.forEach.call( elementList, function( node ) {
node.parentNode.removeChild( node );
});
Upvotes: 0