user3341821
user3341821

Reputation: 3

How to change one line but keep another?

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

Answers (2)

LudovicL
LudovicL

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-heads element that doesn't have the .chat-container class.

Upvotes: 3

szydan
szydan

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

Related Questions