R
R
Ruslan2020-12-26 21:40:00
JavaScript
Ruslan, 2020-12-26 21:40:00

How to remove an element from an event?

Good day to all. I have this li, which is created in js:

task.innerHTML = `<b>${taskNameInput}</b><br/><i>${taskInput}</i><button class = 'item-btn'>Удалить</button>`

I need a specific event to fire when clicking anywhere except the button , my method doesn't work, the event still fires when the button is clicked. What's wrong?
document.querySelector('.task-item').addEventListener('click', function(ev){
        if (ev.target.tagName === 'LI' || 'B' || 'I' && ev.target.className != '.item-btn') {
            alert('dfdf')
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MagnusDidNotBetray, 2020-12-26
@Lorelin

What's wrong?

The button has a class item-btnbut no class .item-btn
A at all. some strange checks, it can be simpler.
({ target }) => {
  if(target.closest('.item-btn')) {
    return
  }
  // остальной код...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question