удаление через remove
Deleteblock.remove() is not function может мне кто объяснить почему он считает его не функцией ??? как это исправить? просто не понятно , что для него функция , а что нет?
const deletePlace = document.querySelectorAll('.element__heart');
const Deleteblock = document.querySelectorAll('.block')
function del() {
Deleteblock.remove();
}
deletePlace.forEach(function(ele) {
ele.addEventListener('click', del)
})
.element__heart {
margin: 31px 22px 30px 0;
background-color: red;
background-position: center;
background-repeat: no-repeat;
border: 0;
width: 21px;
height: 18px;
}
.block {
background: black;
width: 100px;
height: 100px;
margin-right: 10px
}
.box {
display: flex
}
<div class='box'>
<div class='block'>
<button class="element__heart" type="button">1</button>
</div>
<div class='block'>
<button class="element__heart" type="button">2</button>
</div>
<div class='block'>
<button class="element__heart" type="button">3</button>
</div>
<div class='block'>
<button class="element__heart" type="button">4</button>
</div>
</div>
Ответы (1 шт):
Автор решения: Igor
→ Ссылка
const deletePlace = document.querySelectorAll('.element__heart');
function del() {
this.closest('.block').remove();
}
deletePlace.forEach(function(ele) {
ele.addEventListener('click', del)
})
.element__heart {
margin: 31px 22px 30px 0;
background-color: red;
background-position: center;
background-repeat: no-repeat;
border: 0;
width: 21px;
height: 18px;
}
.block {
background: black;
width: 100px;
height: 100px;
margin-right: 10px
}
.box {
display: flex
}
<div class='box'>
<div class='block'>
<button class="element__heart" type="button">1</button>
</div>
<div class='block'>
<button class="element__heart" type="button">2</button>
</div>
<div class='block'>
<button class="element__heart" type="button">3</button>
</div>
<div class='block'>
<button class="element__heart" type="button">4</button>
</div>
</div>