[removed] Click anywhere in body except the one element inside it

前端 未结 4 816
温柔的废话
温柔的废话 2021-02-13 13:43

I want to be able to click anywhere inside the body except that one specific element. I can\'t find out what\'s wrong with the code I have done.

When I click on the one

4条回答
  •  终归单人心
    2021-02-13 14:26

    You are missing one piece to this. You need to stop the event from bubbling up from the except object if it is clicked

    except.addEventListener("click", function(event){event.stopPropagation()}, false);
    

提交回复
热议问题