JSFiddle - React, Tailwind, and code Playground

by TCloud

HTML

<div class="item">
  Первый блок
</div>

<div data-id="second-item" class="item">
  Второй блок
</div>

<div class="item">
  Третий блок
</div>

<button class="remove-btn">
  Удалить второй элемент
</button>

CSS

.item {
  width: 100px;
  height: 100xp;
  border: 1px solid #ddd;
  padding: 20px;
  box-sizing: border-box;
  margin: 10px;
}

JavaScript

// Тут удаляем элемент, по которому кликнули
$(".item").click(function(){
	$(this).remove()
})

// Тут передаем элемент, который надо удалить
$(".remove-btn").click(function(){
  //В переменной будет второй блок
  let secondEl = $(".item[data-id='second-item']");
  removeElement(secondEl)
})

function removeElement(el){
	el.remove()
}